resizing image in java

Discussion in 'Programmer's Corner' started by onebird, Dec 9, 2011.

  1. onebird

    Thread Starter New Member

    Mar 27, 2010
    16
    1
    I am working on a small hobby project, in which i need to re-size my images to a fixed size of 180x230 pixels. To do that, I'm using the method below:

    Code ( (Unknown Language)):
    1. private Image scale(Image src) {        
    2.         int w = 180;      
    3.         int h = 230;
    4.         int type = BufferedImage.TYPE_INT_RGB;
    5.         BufferedImage dst = new BufferedImage(w, h, type);
    6.         Graphics2D g2 = dst.createGraphics();
    7.         g2.drawImage(src, 0, 0, w, h,null);
    8.         g2.dispose();
    9.                        
    10.         return (new ImageIcon(dst)).getImage();
    11.     }
    For some reason, my images are returning all blacked out, I have no idea why. But if I use my images without resizing them with this method, they are displayed correctly. Any hints or pointers on how I can fix this problem? any help would be greatly appreciated
     
  2. onebird

    Thread Starter New Member

    Mar 27, 2010
    16
    1
    I don't know, if I am unclear in my question. But I'm wondering if its just that no-one can help me or what
     
  3. redimage

    New Member

    May 8, 2013
    2
    0
    here is some codes in C# image reisize
    public static void ResizeImageDemo()
    {
    string fileName = "c:/Sample.png";

    REImage reImage = REFile.OpenImageFile(fileName);

    ImageProcessing.applyResize(reImage, 500, 500);

    REFile.SaveImageFile(reImage,"c:/reimage.png", new PNGEncoder());
    }
     
  4. Michael620

    New Member

    May 8, 2013
    7
    0
    I don't know, if I am unclear in my question. But I'm wondering if its just that no-one can help me or what
     
    Last edited by a moderator: May 9, 2013
Loading...