打扰一下,我想问一下如何从该库中检索图像吗?
https://github.com/akshay2211/PixImagePicker
我不知道如何从该库中检索图像。我想展示我的主要活动。 我已经尝试从指南添加此代码
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == RequestCode) {
ArrayList<String> returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);
}
}
这是我使用glide检索图像的源代码
for (int i = 0; i < returnValue.size(); i++) {
String path = returnValue.get(i);
StringBuilder builder = new StringBuilder(path);
builder.deleteCharAt(0);
File file = new File(builder.toString());
Uri imageUri = Uri.fromFile(file);
Glide.with(this)
.load(imageUri)
.onlyRetrieveFromCache(true)
.into(imageView);
System.out.println("value : " + returnValue.get(i));
//LoadImageFromWebOperations(returnValue.get(i));
}
我总是会收到这样的错误
W/Glide: Load failed for file:///storage/emulated/0/DCIM/Camera/IMG_20191116_110843.jpg with size [1080x1542]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
答案 0 :(得分:0)
在源代码中,它包含图像URL的列表: 来源:https://github.com/akshay2211/PixImagePicker/blob/master/pix/src/main/java/com/fxn/pix/Pix.java
ArrayList<String> list = new ArrayList<>();
for (Img i : selectionList)
{ list.add(i.getUrl()); // Log.e("Pix images", "img " + i.getUrl());
}
Intent resultIntent = new Intent(); resultIntent.putStringArrayListExtra(IMAGE_RESULTS, list);
因此,您需要遍历URL列表并加载相应的图像。
以下是一种这样的方法:
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
答案 1 :(得分:0)
for (int i = 0; i < returnValue.size(); i++) {
String path = returnValue.get(i);
System.out.println ( "path: " + path);
Glide.with(this)
.load(path)
.onlyRetrieveFromCache(true)
.into(imageView);
break; // load only one image in the imageview
}
请告知path
的值。
.onlyRetrieveFromCache(true)
我不知道这是否正确。
您需要在清单中
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
并且您应该添加代码以在运行时要求用户确认该权限。
returnValue.size()
的值是什么?