Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change image shape in android

I got success in implementing a pinch zoom in/out and drag/drop functionality in images on the canvas.

Now what I want is re-sizing, that images like below link that based on iPhone Appenter image description here

How to change shape of an image using iPhone SDK?

So how can I achieve that kind of functionality in Android ?

like image 361
Dhruvil Patel Avatar asked Sep 05 '12 09:09

Dhruvil Patel


2 Answers

Basically you need to invalidate the image and re-draw on the canvas from the beginning ::

img=(ImageView)findViewById(R.id.yourimageidfromxml);

img.onTouchEvent(MotionEvent me)
{
   int X=me.getX(); 
   int Y=me.getY();
   img.invalidate();
   img.repaint(X,Y);

}

void paint(int X,int Y)
{
  img.setWidth(X);
  img.setHeight(Y);
}

Scaling image will transform using repaint on canvas from the beginning

like image 185
Vikalp Patel Avatar answered Oct 31 '22 04:10

Vikalp Patel


If by re-sizing you are referring to "stretching" the Bitmap on the vertical and horizontal plane then you simply modify the rect that the shape (eg. oval) is being drawn into.

For example:

This is your original shape of an oval:

canvas.drawOval(new Rect(0,0,100,100), bluePaint);

This is the same oval, just stretched (resized) on the horizontal plane:

canvas.drawOval(new Rect(0,0,200,100), bluePaint);

I hope this helps.

like image 27
Luke Taylor Avatar answered Oct 31 '22 03:10

Luke Taylor