简体   繁体   English

从图库中获取图像,某些图像甚至无法显示图像路径

[英]Getting images from gallery, some images doesn't show even image path is obtained

I'm trying to fetch all images paths inside the gallery(including subfolders) Its working fine, but some of the images are failing to show as thumbnails 我正在尝试获取图库(包括子文件夹)内的所有图像路径,但工作正常,但是某些图像无法显示为缩略图

*obtaining all paths inside arraylist *获取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();

*setting image inside ImageView *在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);

Use this : 用这个 :

Picasso.with(Context).setLoggingEnabled(true);

To check if there is an error retrieving image in logcat. 检查logcat中是否存在错误检索图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM