0

I want to make a grid view to show thumbnail of photos in folder in sdcard. Image resolution is 3264x2448. I use Notras Universal Image Loader lib with config:

DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.stub)
            .showImageForEmptyUri(R.drawable.stub)
            .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
            .showImageOnFail(R.drawable.ic_launcher).cacheInMemory()
            .cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).defaultDisplayImageOptions(options).build();

And getView() in my custom Adapter:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    final ImageView imageView;
    if (convertView == null) {
        imageView = (ImageView) mInflater.inflate(R.layout.grid_item,
                parent, false);
    } else {
        imageView = (ImageView) convertView;
    }

    mImageLoader.displayImage(mListData.get(position), imageView, options);

    return imageView;
}

But it load image too slow. So please help me to load thumbnail image faster. I don't want to display high quality image, I just want to display fast.

Thanks in advance.

UIL version: 1.8.4 Android version tested on: 2.3.3

VAdaihiep
  • 521
  • 9
  • 19
  • use a viewholder for smooth scrolling and performance. http://developer.android.com/training/improving-layouts/smooth-scrolling.html – Raghunandan May 29 '13 at 10:03
  • @Raghunandan Because my item layout just contain an ImageView so I don't use ViewHolder, I think it's not make image load slower. – VAdaihiep May 29 '13 at 10:06
  • @VAdaihiep can you please tell me how to load sdcard images in Universal Image Loader, i tried but error shows like UIL doesn't support scheme(protocol) by default [/mnt/sdcard/images/Adhisayam_2012/DSC_0122.jpg]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...)) please help me.. – kalandar Jul 10 '13 at 06:02
  • Use very simple: universalImageLoader.displayImage(imageUri, imageView); I think your imageUri do not have "file://" at head. It should be file://mnt/sdcard/images/Adhisayam_2012/DSC_0122.jpg – VAdaihiep Jul 11 '13 at 02:32

2 Answers2

1

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 queryMiniThumbnail with almost same parameters to get the path of the thumbnail.

Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
                         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 ) );
}

you can use this uri in imageloader to view thumbnails

Reference and detailed description

Community
  • 1
  • 1
Mahesh
  • 974
  • 6
  • 12
  • Thank you, I just try it but selectedImageUri is a String but this method require a id in long type. Any suggest? – VAdaihiep May 29 '13 at 10:45
  • *mImageLoader.displayImage(uri, imageView, options);* here uri is Image URI (i.e. it can be web url or "file:///mnt/sdcard/image.png"). – Mahesh May 29 '13 at 10:50
  • Which method is actually need id of long type? Please explain – Mahesh May 29 '13 at 10:52
  • I mean selectedImageURI in here: Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail( getContentResolver(), selectedImageUri, MediaStore.Images.Thumbnails.MINI_KIND, null ); It can be a long or Uri but I dont know how to get Uri from a file's path, like /mnt/sdcard/ABC.JPG? – VAdaihiep May 29 '13 at 11:03
  • You can give uri also instead of long id. **public static final Cursor queryMiniThumbnails (ContentResolver cr, Uri uri, int kind, String[] projection)** – Mahesh May 29 '13 at 11:15
1

Try to use .discCacheExtraOptions(800, 800, CompressFormat.PNG, 0) in configuration. You can vary value "800" depending maximum dimension of device.

nostra13
  • 12,377
  • 3
  • 33
  • 43