Get Thumbnail Uri/Path of the Image Stored in Sd Card + Android

Get thumbnail Uri/path of the image stored in sd card + android

You can use this to get the thumbnail:

Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(
getContentResolver(), selectedImageUri,
MediaStore.Images.Thumbnails.MINI_KIND,
(BitmapFactory.Options) null );

There are two types of thumbnails available:

MINI_KIND: 512 x 384 thumbnail
MICRO_KIND: 96 x 96 thumbnail

OR use [queryMiniThumbnails][1] with almost same parameters to get the path of the thumbnail.

EDIT

Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnails(
getContentResolver(), selectedImageUri,
MediaStore.Images.Thumbnails.MINI_KIND,
null );
if( cursor != null && cursor.getCount() > 0 ) {
cursor.moveToFirst();//**EDIT**
String uri = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) );
}

HTH !

[1]: https://developer.android.com/reference/android/provider/MediaStore.Images.Thumbnails.html#queryMiniThumbnails(android.content.ContentResolver, android.net.Uri, int, java.lang.String[])

Generate Thumbnail From Sdcard in Android Q

This is solution for generate thumbnail of video from storage.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {

thumbnail_bitmap = createThumbnail(RecordPitchActivity.this, path);

} else {
thumbnail_bitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
}
public static Bitmap createThumbnail(Activity activity, String path) {
MediaMetadataRetriever mediaMetadataRetriever = null;
Bitmap bitmap = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(activity, Uri.parse(path));
bitmap = mediaMetadataRetriever.getFrameAtTime(1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
}
return bitmap;
}


Related Topics



Leave a reply



Submit