基本上我的图像路径看起来像这样:/mnt/sdcard/Pictures/image.jpg 我需要以最快的方式从中获取缩略图的路径。
我正在尝试使用 MediaStore.Images.Thumbnails.queryMiniThumbnail,但无论我通过什么,我都会得到空光标。谢谢!
编辑: 这是带来所有图像路径和缩略图路径并将它们存储在字符串中的函数。我需要的是一个返回特定图像路径(/mnt/sdcard/Pictures/image.jpg)的缩略图路径的函数。谢谢
public String getThumbPaths(ThumbContext ctx) {
Uri uri = MediaStore.Images.Thumbnails.getContentUri("external");
Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnails(ctx
.getActivity().getContentResolver(), uri,
MediaStore.Images.Thumbnails.MINI_KIND, null);
int columnIndex = cursor.getColumnIndex(Thumbnails.IMAGE_ID);
String[] filePathColumn = { MediaStore.Images.Media.DATA };
StringBuilder stringBuilder = new StringBuilder();
String id = MediaStore.Images.Media._ID + "=?";
String orientation="1";
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String imageId = cursor.getString(columnIndex);
Cursor images = ctx.getActivity().managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
filePathColumn, id,
new String[] { imageId }, null);
String filePath = "";
if (images != null && images.moveToFirst()) {
filePath = images.getString(images
.getColumnIndex(filePathColumn[0]));
}
ExifInterface exifReader;
try {
exifReader = new ExifInterface(filePath);
orientation=exifReader.getAttribute(ExifInterface.TAG_ORIENTATION);
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
stringBuilder.append(cursor.getString(1) + ";");
stringBuilder.append(filePath + ";");
stringBuilder.append(orientation + ";");
orientation="1";
}
//cursor.close();
return stringBuilder.toString();
}