我正在使用它来Bitmap
从现有的旋转:
private Bitmap getRotatedBitmap(Bitmap bitmap, int angle) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(angle);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
是否可以在不创建新位图的情况下做到这一点?
我试图用以下方法重绘相同的可变图像Canvas
:
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
Canvas canvas = new Canvas(targetBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2);
canvas.drawBitmap(targetBitmap, matrix, new Paint());
但这种方法刚刚导致位图损坏。那么有没有可能实现呢?