【问题标题】:Android: What is the correct way to rotate a bitmap?Android:旋转位图的正确方法是什么?
【发布时间】:2014-10-24 08:26:42
【问题描述】:

问题是当位图旋转“R0”度时,看起来好像它改变了轴心点。我想要的是它围绕位图的中间旋转,但我不知道如何。

Bitmap bitmap = (Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.base);
       Matrix matrix = new Matrix();
       matrix.reset();
       matrix.setScale(bitmap.getWidth(), bitmap.getHeight());
       matrix.setTranslate(-bitmap.getHeight()/2, -bitmap.getHeight()/2);
       matrix.postRotate(R0);
       Bitmap b = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
       canvas.drawBitmap(b, x-24, y-40, null);

非常感谢。

【问题讨论】:

  • 我会删除:matrix.setTranslate(-bitmap.getHeight()/2, -bitmap.getHeight()/2);-24-40canvas.drawBitmap(b, x-24, y-40, null);

标签: android matrix bitmap rotation


【解决方案1】:

尝试使用矩阵。postTranslate,而不是setTranslate,后者将重置您的矩阵,setScale 调用将无效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 2015-04-22
    • 2015-12-17
    相关资源
    最近更新 更多