我试图获取图库中的所有图像路径(包括子文件夹)它的工作正常,但有些图像无法显示为缩略图
*获取arraylist中的所有路径
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DATE_TAKEN,
};
final Cursor cursor = getActivity().getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
null, null,
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if (cursor.moveToFirst()) {
final String imageLocation = cursor.getString(1);
locations.add(imageLocation);
while (cursor.moveToNext()) {
String tempLocation = cursor.getString(1);
boolean fileExists = new File(tempLocation).isFile();
if (fileExists) {
locations.add(tempLocation);
}
}
cursor.close();
*在ImageView中设置图像
Uri uri = Uri.fromFile(new File(mItems.get(position)));
Picasso.with(getContext())
.load(uri)
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.placeholder_media)
.error(R.drawable.placeholder_error_media)
.noFade()
.into(mMediaThumb);
答案 0 :(得分:0)
使用此:
{{1}}
检查在logcat中检索图像是否有错误。