2

I want to rotate a imageview around a point. The imageview is referring to a drawable resource.

Then I am converting the imageview to bitmap so that i can draw it on canvas.

With the help of this i am able to draw the drawable on the canvas

    imageView = new ImageView(this);
    imageView.setImageResource(drawable);
    imageView.setDrawingCacheEnabled(true);
    imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    imageView.layout(0, 0, imageView.getMeasuredWidth(), imageView.getMeasuredHeight());
    imageView.buildDrawingCache(true);
    Matrix matrix = new Matrix();
    matrix.setRotate(30,x, y);
    canvas.drawBitmap(imageView.getDrawingCache(), matrix, paint);

The matrix is not working. The image is not rotaing at the point x, y.

Can anyone tell me what i am missing in my code ?

Community
  • 1
  • 1
Akash Patra
  • 768
  • 1
  • 9
  • 20

1 Answers1

0

1st translate(fix) the matrix at the point and then rotate with respective to that point.

Matrix matrix = new Matrix();
matrix.setTranslate(x,y);
matrix.postRotate(30,x, y);
canvas.drawBitmap(imageView.getDrawingCache(), matrix, paint);
midhunhk
  • 5,560
  • 7
  • 52
  • 83