Home » Category » Java Essentials

Java Essentials: Zoom in/out Image

300| Mon, 24 Sep 2007 00:44:00 GMT| servant_aka| Comments (4)
Hi guys,In my Applet , I'm drawing some shapes (ovals and lines) .I need to add zooming functionality , so that when i click zoom in button the Image is scaled correspondly.can someone suggest a way to do that ?thanks.

Keywords & Tags: zoom, out, image, java, essentials

URL: http://java.itags.org/java-essentials/81069/
 
«« Prev - Next »» 4 helpful answers below.
Yeah. I'd be interested in that too.The only suggestion I have is to change the size of what you are drawing by some factor. And also the location.If you are using drawImage(), it will do the scaling for you.

a_sailora | Sun, 15 Jul 2007 16:59:00 GMT |

This can easily be done using a zoom factor

ex:-

double zoomFactor = 1;

/*

when zoomFactor is 1 no zooming is used

when zoomFactor > 1 is zoom In

when zoomFactor < 1 is zoomOut

*/

//paintComponent method

g.drewLine(x1*zoomFactor, y1*zoomFactor, x2*zoomFactor, y2*zoomFactor);

if you want to enable scrolling you will need to impliment the getMaximumSize(), getMinimumSize(), getPreferedSize() methods to return the size by applying the zoomFactor

Every time the zoomFactor changes you have to repaint

lrmka | Sun, 15 Jul 2007 16:59:00 GMT |

> Yeah. I'd be interested in that too.

> The only suggestion I have is to change the size of

> what you are drawing by some factor. And also the

> e location.

>

> If you are using drawImage(), it will do the scaling

> for you.

thanks for you all guys for helping.

yes I'm using drawImage() and wants to know how to do scaling with that ?

If not i'll try to use the zoomFactor method.

can we use the any scaling method for the Graphics object ?

thanks

servant_aka | Sun, 15 Jul 2007 16:59:00 GMT |

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

cecinestpasunprogrammeura | Sun, 15 Jul 2007 16:59:00 GMT |

Java Essentials Hot Answers

Java Essentials New questions

Java Essentials Related Categories