我正在尝试围绕中心旋转图像.这通常使用RotateAnimation,但我希望它更快一点.我现在使用SurfaceView模式和一个单独的绘图线程.
这是代码,它正确绘制位图(取决于外部“标题”)
heading =以度为单位的角度,
bitmap =位图,
w =位图的宽度,
h =位图的高度.
Matrix m = new Matrix();
m.preRotate(heading, w/2, h/2);
m.setTranslate(50,50);
canvas.drawBitmap(bitmap, m, null);
缺点:图像是一个圆圈,上面的代码产生可见的锯齿效果……
下面的代码也是旋转图像,但在旋转时(顺时针方向从0到45度),新图像的中心向下/向右移动.我想,偏心效应是由于新图像的宽度/高度增大了?但是,如果设置了filter = true,则此代码不会产生别名.有没有办法使用代码#1但有一些消除锯齿或使用代码#2但摆脱中心运动?
Matrix m = new Matrix();
m.preRotate(heading, w/2, h/2);
m.setTranslate(50,50);
Bitmap rbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
canvas.drawBitmap(rbmp, 50, 50, null);
更新:作为此线程中讨论的结果,代码#2的正确版本(抗锯齿和正确旋转)将如下所示(忽略50,50的偏移量):
Matrix m = new Matrix();
m.setRotate(heading, w/2, h/2);
Bitmap rbpm = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
canvas.drawBitmap(rbpm, (w - rbpm.getWidth())/2, (h - rbpm.getHeight())/2, null);
谢谢.