【发布时间】:2012-09-13 20:11:47
【问题描述】:
我正在使用它从现有的一个旋转 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());
但是这种方法刚刚导致位图损坏。 那么有没有可能实现呢?
【问题讨论】:
-
尝试获取位并应用矩阵旋转算法
-
这个答案可能会有所帮助:stackoverflow.com/questions/10664006/…
标签: java android image bitmap rotation