安卓 ||位图图像的旋转

标签 android image bitmap out-of-memory

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

最佳答案

尝试 ExifInterface用于图像旋转

检查 this解决方案详情,如何使用ExifInterface

查看有关 Exif 的更多信息

关于安卓 ||位图图像的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40480680/

相关文章:

java - 当用户单击 clickme 按钮时需要显示图像

android - 无法使用 Intent.ACTION_PICK 从库中获取位图

Android WebView 在 scrollTo() 之后损坏绘图

android - FLAG_ACTIVITY_CLEAR_TOP 和 android :launchMode ="singleInstance"

php - 图像/pjpeg 和图像/jpeg

android - flutter Assets 错误 : EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE

css - 如何在半透明图像周围绘制边框? (CSS)

android - 如何从 Android 中的图像文件创建位图

Android 获取当前月份

安卓 : swipe between activities using a single resource