android - BitmapFactory.decodeFile() 不适用于 Adob​​eImageIntent.EXTRA_OUTPUT_URI

标签 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 上运行良好。但是现在我的位图总是返回为空。我已经设置了图像的 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() 不适用于 Adob​​eImageIntent.EXTRA_OUTPUT_URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40483752/

相关文章:

Android - 使用确定的 ProgressDialog 将位图保存到 SD 卡

当设备语言为 en_US 时,Android 7.0 Nougat 会选择默认字符串

android - 为什么 receive_boot_completed 在我的设备上不起作用?

java - SingleValueEvent 显示为空

c# - WPF:如何高效地每秒更新图像 30 次

android.os.FileUriExposedException : file:///storage/emulated/0/test. txt 通过 Intent.getData() 暴露在应用程序之外

java - 从图库中选择图像会出现错误 Android N

Android - ListView滚动太慢

java - 给定 BlobstoreService 提供的 HttpServletResponse,如何获取提供的 blob?

wpf - 如何在 WPF 中拉伸(stretch)位图而不平滑像素