英文:
Error: Required: Image, Found:Image & Parcelable
问题
[![在此输入图片描述][1]][1]
当尝试从图库中获取多个已选择图像时,使用图像数组列表时出现了兼容性问题,如屏幕截图所示。可能的解决方案是什么?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK)
return;
if (requestCode == ConstantsCustomGallery.REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
// 选定图像的路径存储在数组列表中
ArrayList<Image> images = data.getParcelableArrayListExtra(ConstantsCustomGallery.INTENT_EXTRA_IMAGES);
for (int i = 0; i < images.size(); i++) {
Uri uri = Uri.fromFile(new File(images.get(i).path));
// 开始使用图像 URI 进行操作
}
}
}
<details>
<summary>英文:</summary>
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/fTcYe.jpg
While trying to get multiple selected images from gallery, there is a compatible issue as shown in screenshot when i use image array list. What could be the solution?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK)
return;
if (requestCode == ConstantsCustomGallery.REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
//The array list has the image paths of the selected images
ArrayList<Image> images = data.getParcelableArrayListExtra(ConstantsCustomGallery.INTENT_EXTRA_IMAGES);
for (int i = 0; i < images.size(); i++) {
Uri uri = Uri.fromFile(new File(images.get(i).path));
// start play with image uri
}
</details>
# 答案1
**得分**: 1
按照我在评论中所说,您需要导入正确的`Image`。
```java
import in.myinnos.awesomeimagepicker.models.Image;
而不是
import android.media.Image;
英文:
As i said in comments You need to import the right Image
.
import in.myinnos.awesomeimagepicker.models.Image;
instead of
import android.media.Image;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论