how to resize images

can anyone please tell how to resize ie. zoom in\zoom out images.
[80 byte] By [rahul31] at [2007-9-26 7:01:11]
# 1

hi,

i did it like this...

<CODE>

private void repaintImage() {

ImageIcon icon = (ImageIcon)imageLabel.getIcon();

Image img = icon.getImage();

double newWidth = img.getWidth(this) * xFactor;

double newHeight = img.getHeight(this) * yFactor;

Image scaled = img.getScaledInstance((int)newWidth, (int)newHeight, Image.SCALE_SMOOTH);

ImageIcon ii = new ImageIcon(scaled);

imageLabel.setIcon((Icon)ii);

jScrollPane1.setViewportView(imageLabel);

update(getGraphics());

}

</CODE>

i have the following structure

scrollpane contains label which contains imageIcon, this icon can be converted to awt.Image, which provides the method for scaling the image.

i suggest to reload or take a buffered image when before resizing it, because once resized, the quality drops a little bit and as often you resize you loose more quality, so always stretch or shrink the image from the original to get best quality.

hope that helps

chris

191274 at 2007-7-1 16:37:00 > top of Java-index,Security,Cryptography...
# 2
Check out http://www.esus.com/javaindex/j2se/jdk1.2/javaawt/awtgraphics/2dgraphics/images/filterstransforms/filterstransforms.htmlFor code samples.Cheers,Joris
vdbjoris at 2007-7-1 16:37:00 > top of Java-index,Security,Cryptography...
# 3
Thanks a lot man!one-derful solution.
rahul31 at 2007-7-1 16:37:00 > top of Java-index,Security,Cryptography...