• Post Reply Bookmark Topic Watch Topic
  • New Topic

Moving, Dragging, Resizing Images in Canvas

 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!