zoom In/zoom Out an Image

D

dwurity

Hi
I am developing an applet application, and placed an Image,when a
button(zoom In) click ,I have to perform the zoom In function .....

How can I do that...

Thanks in advance,
dwurity
 
K

Keith James

dwurity> Hi I am developing an applet application, and placed an
dwurity> Image,when a button(zoom In) click ,I have to perform the
dwurity> zoom In function .....

dwurity> How can I do that...

e.g. using a JPanel, override paintComponent:

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();

AffineTransform transform = new AffineTransform();
Insets insets = getInsets();
transform.translate(insets.left, insets.top);

// Implement a getScale() method which returns your current scale
double scale = getScale();

// Assumes you want to scale equally on x and y axes
transform.scale(scale, scale);
g2.transform(transform);

// Implement a getImage() method which returns your current Image
Image image = getImage();

if (null != image)
{
g2.drawImage(image, 0, 0, this);
}

g2.dispose();
}

That's one way to do it - then just hook up your button to a setter to
a method setScale(double scale) which changes the scale value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top