[英]Android, rotate bitmap around self center without scale it
当我围绕它旋转位图时,位图图像的大小发生了变化,并且旋转时会晃动。
public static Bitmap RotateBitmap(Bitmap source, int width, float angle) {
Matrix matrix = new Matrix();
int px = width / 2;
matrix.postRotate(angle, px, px);
Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, width, width, matrix, true);
return bitmap;
}
每次在画布上进行绘制时,都会将某些添加到位图的宽度和高度中,并随着摇动而旋转。 如何平稳旋转而不摇动位图?
正在调整大小,因为您传递了一半的宽度。 用这个:
public static Bitmap RotateBitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
return bitmap;
}
至于摇动,必须在另一个线程上调用它。 ( AsyncTask
等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.