【发布时间】:2012-11-04 03:36:30
【问题描述】:
我想根据用户点击将位图图像旋转 10 度。根据大量 stackoverflow 和 google 的回答,我尝试了各种矩阵旋转组合。
但是,图像并没有像预期的那样真正旋转,并且给出了旋转 + 围绕画布中心振荡的抖动视图。为了测试,每次调用对象的绘制方法时,我都会将旋转角度增加 10 度(而不是点击)。图像是一个对称的圆形 [64x64 封闭矩形],我希望它像轮子一样在屏幕中心围绕它自己的中心旋转,但它会旋转并沿对角线向右下方移动,然后以振荡方式回到屏幕中心.
public void draw(Canvas canvas) {
Matrix matrix = new Matrix();
rotation += 10;
float px = this.viewWidth/2;
float py = this.viewHeight/2;
matrix.setRotate(rotation, bitmap.getWidth()/2, bitmap.getHeight()/2);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, getImgWidth(), getImgHeight(), matrix, true);
canvas.drawBitmap(newbmp, px - (getImgWidth()/2), py - (getImgHeight()/2), null);
}
【问题讨论】:
标签: android image rotation smooth