【问题标题】:Android || Rotation of Bitmap Image安卓||位图图像的旋转
【发布时间】: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


【解决方案1】:

尝试ExifInterface 进行图像旋转

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

查看更多关于Exif的信息

【讨论】:

    猜你喜欢
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多