基本上我有圖像路徑,看起來像這樣:/mnt/sdcard/Pictures/image.jpg 而我需要以最快的方式從它得到一個縮略圖的路徑。如何從android中的圖像路徑獲取縮略圖路徑?
我想使用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();
}
發表了一些代碼... – njzk2
queryMiniThumbnail將用於已經插入的圖像 – njzk2