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

前端 未结 8 668
自闭症患者
自闭症患者 2020-11-28 04:46

SDK version - 1.6

I am using following intent to open android\'s default gallery:

Intent intent = new Intent();
                inte         


        
相关标签:
8条回答
  • 2020-11-28 05:17

    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[])

    0 讨论(0)
  • 2020-11-28 05:19

    This solution is work on me!

    final int THUMBSIZE = 128;
    
    Bitmap thumbImage = ThumbnailUtils.extractThumbnail(
                             BitmapFactory.decodeFile(file.getAbsolutePath()), 
                             THUMBSIZE, 
                             THUMBSIZE);
    
    0 讨论(0)
提交回复
热议问题