简体   繁体   中英

Rotating a imageView around a point to some degrees

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 ?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM