对不起,我想问一下如何从该库中检索图像?
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);
}
}
这是我使用滑动获取图像的源代码
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
从源代码中,它包含图像网址的列表:来源: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);
因此,您需要遍历网址列表并加载相应的图像。
以下是一种这样的方法:
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;
}
}
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)
我不知道这是否正确。