基本上我的图像路径如下:/mnt/sdcard/Pictures/image.jpg 我需要以最快的方式从中获取缩略图的路径。
我正在尝试使用MediaStore.Images.Thumbnails.queryMiniThumbnail,但无论我传递什么,我都会得到null游标。 谢谢!
修改 这是带来所有图像路径和缩略图路径并将它们存储在String中的函数。我需要的是一个返回特定图像路径的缩略图路径的函数(/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();
}
答案 0 :(得分:1)
如果我理解正确,您的图片不在媒体数据库中。你可以使用
ThumbnailUtils.extractTumbnail()
只需要一个位图。
答案 1 :(得分:-1)
试一试。它可以帮助您将图像缩略图设置为ImageView。
im=(ImageView)findViewById(R.id.imageView1);
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
//InputStream is=getAssets().open("apple-android-battle.jpg");
FileInputStream fis = new FileInputStream("/sdcard/apple.jpg");
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
Float width = new Float(imageBitmap.getWidth());
Float height = new Float(imageBitmap.getHeight());
Float ratio = width/height;
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
im.setImageBitmap(imageBitmap);
}
catch(Exception ex) {
}
希望它会对你有所帮助。