如何从库图像选择器中检索图像 android
how to retrieve image from library image picker android
请问如何从这个库中检索图像?
https://github.com/akshay2211/PixImagePicker
我不知道如何从该库中检索图像。我想在我的主 activity 上展示。
我一直在尝试从指南中添加此代码
@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
从源代码来看,它包含一个图像网址列表:
资料来源: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;
}
}
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()
的值是多少?
请问如何从这个库中检索图像?
https://github.com/akshay2211/PixImagePicker
我不知道如何从该库中检索图像。我想在我的主 activity 上展示。 我一直在尝试从指南中添加此代码
@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
从源代码来看,它包含一个图像网址列表: 资料来源: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;
}
}
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()
的值是多少?