获取图像缩略图文件路径 [英] Get images thumbnail file paths

查看:95
本文介绍了获取图像缩略图文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取缩略图路径,而不是位图对象.
当我查询这些时,某些缩略图路径由于某些原因而为空. (我的设备中有1028张缩略图,光标长度的确是1028,但仍返回空值)我知道有1028张缩略图,因为我检查了一下. 这是我的代码:

I'm trying to get the thumnail paths, not the bitmaps objects.
When I query for these, some of the thumbnail paths are null for some reason. (I have 1028 thumbnail images in my device, the cursor length is indeed 1028, but still returning nulls) I know there are 1028 thumbnail images because I checked. Here's my code:

     String[] projection = {MediaStore.Images.Thumbnails._ID};
  // Create the cursor pointing to the SDCard

  cursor = this.getContentResolver().query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
          projection, // Which columns to return
          null,       // Return all rows
          null,
          MediaStore.Images.Thumbnails.IMAGE_ID);
  // Get the column index of the Thumbnails Image ID
  Log.d(Global.TAG, "BEFORE");
  columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
  Log.d(Global.TAG, "AFTER1");
  for(int i =0;i<cursor.getCount();i++){
      cursor.moveToPosition(i);

      Log.d("MyTag","BBABA" + i +" : " + getThumbnailPathForLocalFile(cursor.getLong(columnIndex)));
  }
  cursor.close();

我的getThumbnailPathForLocalFile:

My getThumbnailPathForLocalFile:

    String getThumbnailPathForLocalFile(long fileId)
 {
    // Log.d(Global., msg)
     Cursor thumbCursor = null;
     try
     {
         thumbCursor = this.getContentResolver().
                 query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI
                 , null
                 , MediaStore.Images.Thumbnails.IMAGE_ID + " = " + fileId+ " AND "
                   + MediaStore.Images.Thumbnails.KIND + " = "
                   + MediaStore.Images.Thumbnails.MINI_KIND , null, null);

         if(thumbCursor.moveToFirst())
         {
             // the path is stored in the DATA column
             int dataIndex = thumbCursor.getColumnIndexOrThrow( MediaStore.MediaColumns.DATA );
             String thumbnailPath = thumbCursor.getString(dataIndex);
             return thumbnailPath;
         }
     }
     finally
     {
         if(thumbCursor != null)
         {
             thumbCursor.close();
         }
     }

     return null;
 }

这是我的日志: http://pastebin.com/UZLZF9Pg

检查后,我发现发送的ID就像for循环的索引一样. 我什至不确定我的代码是否可以正常工作,因此任何其他代码都很棒.

After checking, I see that the ids I send are just like the index of the for loop. I'm not even sure that my code is supposed to work, so any other code will be great.

推荐答案

您应查询 MediaStore.Images.Thumbnails.DATA .要修改您的示例,它看起来像这样.

You should query for MediaStore.Images.Thumbnails.DATA. To modify your example, it would look like this.

String[] projection = {MediaStore.Images.Thumbnails.DATA};
// Create the cursor pointing to the SDCard

    Cursor cursor = this.getContentResolver().query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
        projection, // Which columns to return
        null,       // Return all rows
        null,
        null);
// Get the column index of the Thumbnails Image ID
Log.d(TAG, "BEFORE");
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
Log.d(TAG, "AFTER1");
for(int i =0;i<cursor.getCount();i++){
    cursor.moveToPosition(i);

    Log.d("MyTag","BBABA" + i +" : " + cursor.getString(columnIndex));
}
cursor.close();

参考:如何从缩略图路径获取图像路径图片?

这篇关于获取图像缩略图文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆