简体   繁体   English

围绕某个点旋转imageView一定程度

[英]Rotating a imageView around a point to some degrees

I want to rotate a imageview around a point. 我想围绕一个点旋转imageview。 The imageview is referring to a drawable resource. imageview指的是可绘制资源。

Then I am converting the imageview to bitmap so that i can draw it on canvas. 然后我将imageview转换为位图,以便可以在画布上绘制它。

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. 图像在点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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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