VAdaihiep
VAdaihiep

Reputation: 531

How to load image (from sdcard) faster in thumbnail size?

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

Upvotes: 0

Views: 4140

Answers (2)

nostra13
nostra13

Reputation: 12407

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

Upvotes: 1

Mahesh
Mahesh

Reputation: 984

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

Upvotes: 1

Related Questions