请建议我在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();
}
}