gpt4 book ai didi

android - 使用 Glide 将图像加载到 ImageView 中,Uri 从 Intent 返回, Action 为 ACTION_GET_CONTENT

转载 作者:行者123 更新时间:2023-11-30 00:06:03 25 4
gpt4 key购买 nike

我正在尝试使用 Glide 库在 ImageView 中显示图像。我正在使用 OnActivityResult 中返回的 Uri(Intent.getData()) 在 ImageView 中显示。我打算按如下方式选择图像:

Intent intent = new Intent();

intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select an image"),77);

那么OnActivityResult中返回的Uri是这样的:

content://com.android.providers.media.documents/document/image%3A21300

在 OnActivityResult 中我做了以下事情但是图像没有显示在 ImageView 中:

Uri uri = data.getData();
Log.e("uri", uri.toString());
addedImageView.setVisibility(View.VISIBLE);
GlideApp.with(this).load(uri).placeholder(new ColorDrawable(Color.RED)).into(addedImageView);

到目前为止,我只看到人们使用带“file://”前缀的 Uri,但从未见过带“content://”前缀的人。如何使用带有 Glide 的“content://”uri 将图像加载到 ImageView 中?

最佳答案

确保你已经添加了

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

进入您的 list ,如果您的 targetSdk >= 23,您还执行了运行时权限检查。

此外,尝试使用 Uri 中的 File 实例并加载它

GlideApp.with(this).load(new File(uri.getPath())).placeholder(new ColorDrawable(Color.RED)).into(addedImageView);

关于android - 使用 Glide 将图像加载到 ImageView 中,Uri 从 Intent 返回, Action 为 ACTION_GET_CONTENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48987795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com