【问题标题】:Rotating a imageView around a point to some degrees围绕一个点将 imageView 旋转到一定程度
【发布时间】:2012-09-26 09:32:01
【问题描述】:

我想围绕一个点旋转图像视图。 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 处没有旋转。

谁能告诉我我的代码中缺少什么?

【问题讨论】:

    标签: android canvas matrix bitmap imageview


    【解决方案1】:

    第一次平移(固定)该点的矩阵,然后分别旋转到该点。

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

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 2012-11-21
      • 2023-04-03
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多