请建议我在 android 中旋转位图图像的方法。
我有以下示例,但是当我将图像旋转 10 度时,它的角变黑并且图像尺寸增加。
当我连续旋转图像 10 度时,它抛出内存超出绑定(bind)异常。
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();
}
}
最佳答案
关于安卓 ||位图图像的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40480680/