Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

zooming an image / imageicon

 
tony navaratnam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a basic drawing program that uses a imageicon on a jlabel as a canvas.
An image is chosen and an icon is created from it to use with seticon.It is drawn onto later by getgraphics and then drawLine etc.

Is it possible to zoom the icon of the label using a slider/buttons??
If i could be sent to a example,that would be handy.
If it is possible, can area selected using the mouse be specificallly zoomed??

I already have a built in way to record what has been drawn on the canvas.It records as x-y co-ordinates. what changes will be needed for zooming?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to zoom the icon of the label using a slider/buttons??
Yes. Both work well. With a button you make small increments, eg, 0.01, to the scale (member variable). With a slider you can set the scale directly.
If i could be sent to a example,that would be handy.
Examples have been posted on this forum and on the Java2D forum at sun.
If it is possible, can area selected using the mouse be specificallly zoomed??
Yes. There are many ways to do this. You could scale the entire image with AffineTransform and position it in your label so the (clipping) rectangle is centered. Or you can get a subimage using the rectangle dimensions/location, copy it (to avoid changes made to the subimage causing affects in the source image) and scale to the desired size.
I already have a built in way to record what has been drawn on the canvas.It records as x-y co-ordinates. what changes will be needed for zooming?
Care to properly align the clipping rectangle over the image. If their origins are different you will need to make adjustments to align them to avoid RasterFormatExceptions.
This is based on the assumption that you are using BufferedImages for this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic