3

我最近用最新版本更新了 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。但现在我的位图总是返回为空。我已经设置了图像的 URI,就像在这篇文章中提到的那样: https ://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat /zh。我还尝试使用 BitmapFactory.Options 调整位图的大小,认为图像可能太大了。但似乎并非如此。

4

1 回答 1

2

如果您必须Uri图像,最好通过以下方式阅读ContentResolver

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

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

于 2016-11-08T10:02:42.220 回答