Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Universal Image Loader Load Large Image

I need to load large image which has 2450 x 2450 pixels dimensions.

Bitmap bitmap = ImageLoader.getInstance().loadImageSync(url,
        ImageConfig.getImageOptions());

The problem is, on low end device (phone with less than 1 GB RAM), got out of memory exception.

This is my DisplayImageOptions

public static DisplayImageOptions getImageOptions() {
    DisplayImageOptions.Builder options = new DisplayImageOptions.Builder();
    options.delayBeforeLoading(10)
            //The reason I'm using ARGB_8888 because I need to load bitmap without losing it's quality
            .bitmapConfig(Bitmap.Config.ARGB_8888)
            .imageScaleType(ImageScaleType.NONE)
            //I'm not using disk or memory cache
            .cacheOnDisk(false)
            .cacheInMemory(false);
    return options.build();
}

I tried to add target size based on device resolution, but it's not working, loaded bitmap still has 2450 x 2450 pixels dimensions.

int height = orientation == Configuration.ORIENTATION_PORTRAIT ?
        displaymetrics.heightPixels : displaymetrics.widthPixels;

Bitmap bitmap = ImageLoader.getInstance().loadImageSync(imageUri,
        new ImageSize(height, height), ImageConfig.getImageOptions());

I tried to change imageScaleType to ImageScaleType.EXACTLY, loaded bitmap resized to 1225 x 1225 pixels, on all device, I need to get original dimensions for high end device, and resized dimensions for low end device.

The main problem is target size is not working

Any idea how should I load the image, especially for low end device?

like image 718
user2341387 Avatar asked Oct 30 '22 16:10

user2341387


1 Answers

try to use some library like Picasso.

It is really easy to use and it manage resize for you.

If you want to do this by yourself, I suggest to do it with NDK in c++, because there you have a better memory management and can help you with low end devices.

like image 192
Sergey Avatar answered Nov 11 '22 11:11

Sergey