【发布时间】:2015-05-05 01:19:04
【问题描述】:
我有一个位图,我想围绕画布上的一个点进行旋转。我要旋转它的点不是位图的中心。我正在使用矩阵。这是我所拥有的一个示例。
Bitmap image = ContentManager.getInstance().getImage(imageId);
Matrix matrix = new Matrix();
matrix.setTranslate(-image.getWidth()/2f, -image.getHeight()/2f);
matrix.postRotate(rotationDegrees);
matrix.postTranslate(x / scaleX, y / scaleY);
matrix.postScale(scaleX, scaleY);
paint.setAlpha(alpha);
canvas.drawBitmap(image, matrix, paint);
我想稍微操纵这段代码,使其不围绕位图的中心点旋转,而是围绕不同的点旋转。为了更清楚地说明,我创建了这张图片:
我已经尝试了所有我能想到的设置
matrix.setTranslate(-image.getWidth()/2f, -image.getHeight()/2f);
到
matrix.setTranslate(pivotPoint.x, pivotPoint.y);
还有很多其他的东西。结果是位图总是偏离我预期的位置。 (例如,将其围绕屏幕中心旋转 90 度会使位图与原来的位置成 90 度,因此会被旋转。)位图似乎总是围绕其中心点旋转,然后最终出现在屏幕上的一个随机点屏幕。
【问题讨论】:
标签: java android bitmap rotation