O
OtisUsenet
Hi,
I need to scale / resize an image and create a thumbnail out of it.
I'm using the Java2D approach (i.e. using only Java's image
manipulation API without external libraries), but I'm getting
thumbnail images that are of visibly lower quality than originals (and
significantly lower quality than when I resize images with, say, a
commandline ImageMagick tool (mogrify).
Is there *any* way not to lose image quality *significantly* when
resizing images with Java2D?
Here is the code I'm currently using:
public static BufferedImage scaleImage(InputStream srcImage, int
width, int height) throws IOException {
BufferedImage bsrc = ImageIO.read(srcImage);
BufferedImage bdest = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bdest.createGraphics();
AffineTransform at =
AffineTransform.getScaleInstance((double)width/bsrc.getWidth(),
(double)height/bsrc.getHeight());
g.drawRenderedImage(bsrc, at);
return bdest;
}
Any help or pointers would be appreciated. Thank you!
I need to scale / resize an image and create a thumbnail out of it.
I'm using the Java2D approach (i.e. using only Java's image
manipulation API without external libraries), but I'm getting
thumbnail images that are of visibly lower quality than originals (and
significantly lower quality than when I resize images with, say, a
commandline ImageMagick tool (mogrify).
Is there *any* way not to lose image quality *significantly* when
resizing images with Java2D?
Here is the code I'm currently using:
public static BufferedImage scaleImage(InputStream srcImage, int
width, int height) throws IOException {
BufferedImage bsrc = ImageIO.read(srcImage);
BufferedImage bdest = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bdest.createGraphics();
AffineTransform at =
AffineTransform.getScaleInstance((double)width/bsrc.getWidth(),
(double)height/bsrc.getHeight());
g.drawRenderedImage(bsrc, at);
return bdest;
}
Any help or pointers would be appreciated. Thank you!