您好我正在从Android MediaStore中将图片加载到网格中,就像这样
private ArrayList<ImageItem> loadImageData() {
Cursor cursor;
int columnIndex;
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Thumbnails._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Thumbnails.DATA};
// Create the cursor pointing to the SDCard
cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
// Get the column index of the Thumbnails Image ID
int imageID;
cursor.moveToFirst();
final ArrayList<ImageItem> imageItems = new ArrayList<>();
for (int i = 0; i < cursor.getCount(); i++) {
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
imageID = cursor.getInt(columnIndex);
int nameIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
int fullImageIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String uri = "file://" + cursor.getString(fullImageIndex);
int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);
String TbUri = "file://" + cursor.getString(thumbIndex);
imageItems.add(new ImageItem(TbUri, cursor.getString(nameIndex), uri));
cursor.moveToNext();
}
cursor.close();
return imageItems;
}
然后我将大拇指添加到网格
Picasso.with(gridContext).load(item.getImage()).fit().centerCrop().into(Holder.image);
在Android 4.0.1设备上这个代码工作正常。
但是在Android 7.1上我得到了很少的图像加载到网格中,其余的都丢失了。 未显示的图像是使用设备相机拍摄的JPEG。下载文件夹或whatsApp中的图像显示正确。
在logcat中我收到以下错误:
e: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface. java.io.IOException: Invalid marker: 89
这可能与缩略图有关吗?因为我使用:
int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);
String TbUri = "file://" + cursor.getString(thumbIndex);
答案 0 :(得分:0)
降级到Picasso版本2.4.0似乎解决了这个问题。也可能与设备有关。我的设备是onePlus 3 7.1.1希望这可以帮助别人。