我最近用最新版本更新了 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/en .我还尝试使用 BitmapFactory.Options 调整位图的大小,认为图像可能太大了。但似乎并非如此。
最佳答案
如果你有 Uri
图像,最好通过 ContentResolver
读取它:
Uri uri;
Context context;
try {
Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ContentResolver
为您处理底层存储差异。它同样适用于 file://
、content://
和其他 Uri
类型。
关于android - BitmapFactory.decodeFile() 不适用于 AdobeImageIntent.EXTRA_OUTPUT_URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40483752/