Java 2D - Resizing BufferedImage
I need to resize a BufferedImage that is of very high quality. The picture is as much as 8Mb, and that’s why I want to downsize it before saving in my DB. Anyway, my routine workd fine on smaller pictures, but when the picture gets this big, it simply stops. Anyone knows a better way of resizing pictures?
My code is:
BufferedImage img = ImageIO.read(picFile);
Image tmpimg = img.getScaledInstance(-1, 70, 0);
JLabel lbl = new JLabel(”");
loadImage(tmpimg, lbl);
int w = tmpimg.getWidth(null);
int h = tmpimg.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BuffferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(tmpimg, 0,0, w, h, null);
g2d.dispose();
Then the bi should be right size, which it is normally, just that such large pictures stops the whole application. I have set -Xmx512m, and have a pretty good PC (1Gb+ RAM).
And the loadImage function is: Read the rest of this entry »
- January 17th, 2009
- Java Programming, Programming
- Comments (11)




