Android Universal Image Loader - how to properly set specifications?

I have an application that uploads a large number of large images remotely. When I use the nostra universal image downloader ( https://github.com/nostra13/Android-Universal-Image-Loader ), I often get Out Of Memory errors. I do not know how to configure the image downloader to prevent this.

These are my current ImageLoader specifications:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .enableLogging()
        .memoryCache(new WeakMemoryCache())
        .build(); 

this.imgDispOpts = new DisplayImageOptions.Builder()
        .cacheInMemory() 
        .cacheOnDisc() 
        .imageScaleType(ImageScaleType.IN_SAMPLE_INT) 
        .build();

this.imageLoader = ImageLoader.getInstance();
this.imageLoader.init(config);

And yes, I pass imgDispOpts when calling displayImage ().

+5
source share
4 answers

Do not try to be cached in memory, use the type of scale EXACTLYand RGB_565for bitmap decoding.

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .enableLogging()
    .build(); 

this.imgDispOpts = new DisplayImageOptions.Builder() 
    .cacheOnDisc() 
    .imageScaleType(ImageScaleType.EXACTLY) 
    .bitmapConfig(Bitmap.Config.RGB_565)
    .build();
+5
source

, .

com.nostra13.universalimageloader.core.decode BaseImageDecoder.java,

public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
        Bitmap decodedBitmap;
        ImageFileInfo imageInfo;

        InputStream imageStream = getImageStream(decodingInfo);
        try {
            imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
            imageStream = resetStream(imageStream, decodingInfo);
            Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);

// add in the decodingOptions here:

decodingOptions.inSampleSize = 10; // or any number

// or you can calculate the resample rate by using the screen size / grid size and the image size

decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions);
    } finally {
        IoUtils.closeSilently(imageStream);
    }
    if (decodedBitmap == null) {
        L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
    } else {
        decodedBitmap = considerExactScaleAndOrientaiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation, imageInfo.exif.flipHorizontal);
    }
    return decodedBitmap;
}
+1

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .enableLogging()
     discCacheExtraOptions(maxImageWidthForDiscCache, maxImageHeightForDiscCache, CompressFormat.PNG, 0);
    .memoryCache(new WeakMemoryCache())
    .build();

 this.imgDispOpts = new DisplayImageOptions.Builder()
    .cacheInMemory() 
    .cacheOnDisc() 
    .imageScaleType(ImageScaleType.EXACTLY) 
    .build();

Lazy . https://github.com/thest1/LazyList.

LazyList. LazyList.

0

, :

ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context)
//Add these lines to your ImageLoader configuration
        .threadPriority(Thread.NORM_PRIORITY - 2);
        .denyCacheImageMultipleSizesInMemory();
        .diskCacheExtraOptions(150, 150, null); // You may change image resolution to fit your needs


ImageLoader.getInstance().init(config.build());
0

All Articles