Android ||位图图像的旋转

时间:2016-11-08 06:53:18

标签: android image bitmap out-of-memory

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

1 个答案:

答案 0 :(得分:2)

尝试使用ExifInterface进行图像旋转

检查this解决方案以获取详细信息,如何使用ExifInterface

查看有关Exif

的更多信息
相关问题