0

I wrote this little resize method to scale .png pictures:

    public BufferedImage resize(BufferedImage img, int newW, int newH) {
    int w = img.getWidth();
    int h = img.getHeight();
    BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
    Graphics2D g = dimg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(img, 0, 0, newH, newW, 0, 0, w, h, null);
    g.dispose();
    return dimg;
}

I want to make my .png picture at least 8 times bigger, but this fcks up the resolution of the image. Does anyone know how to solve this?

Thanks.

Simon Huenecke
  • 97
  • 1
  • 1
  • 7

2 Answers2

1

What you could do if you wish to is use the Image.getscaledinstance then render it. For example

resizedimage = image.getScaledInstance(newW, newH, Image.SCALE_SMOOTH));

Only thing is you would have to change you method to work with a Image instead of a BufferedImage but that is easily done.

Alex Finch
  • 34
  • 1
  • 7
0

you can try this :

BufferedImage createResizedCopy(BufferedImage img, int newW, int newH)
{
    BufferedImage scaledBI = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = scaledBI.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.drawImage(img, 0, 0, newW, newH, null); 
    g.dispose();
    return scaledBI;
}

Or go see here , an other people have the same issue.

Albanninou
  • 409
  • 2
  • 11