将图像围绕某个点旋转一定程度

时间:2012-09-26 09:32:01

标签: android canvas matrix bitmap imageview

我想围绕一个点旋转一个imageview。 imageview指的是一个可绘制的资源。

然后我将imageview转换为位图,以便我可以在画布上绘制它。

this的帮助下,我能够在画布上绘制可绘制的

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

矩阵不起作用。图像在x,y点处不旋转。

有人能告诉我我的代码中缺少什么吗?

1 个答案:

答案 0 :(得分:0)

首先在该点处平移(固定)矩阵,然后相应于该点旋转。

Matrix matrix = new Matrix();
matrix.setTranslate(x,y);
matrix.postRotate(30,x, y);
canvas.drawBitmap(imageView.getDrawingCache(), matrix, paint);
相关问题