BitmapFactory.decodeFile()无法使用AdobeImageIntent.EXTRA_OUTPUT_URI

时间:2016-11-08 09:52:19

标签: android bitmap android-7.0-nougat adobecreativesdk

我最近使用最新版本更新了adobecreativesdk以支持Android Nougat。在编辑器中编辑图像后,我尝试使用onActivityResult中的以下代码获取编辑的位图:

  mImageUri = data.getParcelableExtra(AdobeImageIntent.EXTRA_OUTPUT_URI);

                    Bitmap bitmap  = BitmapFactory.decodeFile(mImageUri.getPath());

                    if(bitmap!=null)
                    {

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                   imagebytes = baos.toByteArray();

                    PlayAnimation();
                    }

在更新到最新版本之前,我使用的是data.getData()而不是data.getParcelableExtra,它适用于Android Marshmallow。但现在我的位图始终返回null。我已经设置了图像的URI,就像在这篇文章中提到的那样: https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en。我也尝试使用BitmapFactory.Options调整位图大小,可能是因为图像太大了。但似乎并非如此。

1 个答案:

答案 0 :(得分:1)

如果您要Uri成像,最好通过ContentResolver阅读:

Uri uri;
Context context;
try {
    Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri));
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

ContentResolver为您处理底层存储差异。它同样适用于file://content://和其他Uri类型。