【发布时间】:2016-11-08 06:53:18
【问题描述】:
请建议我在android中旋转位图图像的方法。
我有以下示例,但是当我将图像旋转 10 度时,它会在角落变黑,并且图像的大小会增加。
当我将图像连续旋转 10 度时,它会抛出内存超出范围异常。
private void rotateImage(String sourcePath, float angle) {
Bitmap bitmap = BitmapFactory.decodeFile(sourcePath);
Matrix matrix = new Matrix();
matrix.setRotate(angle);
Bitmap rotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
File file = new File(sourcePath);
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(file);
rotated.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
bitmap.recycle();
rotated.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
-
在你的清单活动标签中添加一行:androidl:LargeHeap=true;
-
你的目标是什么?如果您只想在视图上旋转图像,也许您可以使用 ObjectAnimator。
-
我的目标是做图片旋转应用。
标签: android image bitmap out-of-memory