gpt4 book ai didi

android - 获取图像缩略图文件路径

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:05:59 26 4
gpt4 key购买 nike

我正在尝试获取缩略图路径,而不是位图对象。
当我查询这些时,某些缩略图路径由于某种原因为空。(我的设备里有1028个缩略图,光标长度确实是1028,但还是返回null)我知道有1028个缩略图,因为我查了。这是我的代码:

     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:

    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

查看后,我发现我发送的ids就像for循环的索引一样。我什至不确定我的代码是否应该工作,所以任何其他代码都会很棒。

最佳答案

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

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();

引用:How to get imagepath from thumbnail path of a image?

关于android - 获取图像缩略图文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18172074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com