Forums Register Login

Moving, Dragging, Resizing Images in Canvas

+Pie Number of slices to send: Send
Hi All,
I am having problem in giving the functionality for Dragging, Resizing of images in Canvas.
Actually , I have drawn an image in canvas & now I want that it should be able to be selected by user so that he can resize it , shear it, rotate it etc.
I am trying Graphics2D for it.
I have modified paint method of my canvas class as below :
public void paint(Graphics g) {
System.out.println("In paint of RefreshCanvas");
int w = 25;
int h = 20;
Graphics2D g2 = (Graphics2D)g;
AlphaComposite ac = AlphaComposite.getInstance (AlphaComposite.SRC_OVER,(float)0.8);
g2.scale(0.8,0.8);
g2.setComposite(ac);

if(img==null || img.size()<1) { }
else {
System.out.println("Image found");
for(int i=0; i<img.size(); i++)
{
g2.drawImage((Image)img.elementAt(i),(w*(i+1)),(h*(i+1)),this);
}
if (RText==null || RText.trim().length()<1) {
} else {
//g2.setColor(Color.blue);
g2.setStroke(new BasicStroke(5.0f));
g2.scale(1.4,1.4);
g2.drawString(RText,100,100);
}
}
In above code img is the Vector containing Image objects & RText is the text message entered by user.
With the above code, I am able to display multiple overlapping images & also
some text over it.
But what I want that user should be able to select any of images & can resize, reshape and/or drag it. (A bit similar to as we can select image (Object) in MS PowerPoint and can replace & resize it).
Can anybody help/guide me in achieving this functionality.
Thanks & Waiting for some input.

Manoj Tyagi

The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1734 times.
Similar Threads
Arrow key commands and paint method in canvas (mac vs pc)
Magnifying only a part of the image
topic is on images
How to shrink/grow lines
JPanel PaintComponent method gives OutOfMemoryError
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:53:48.