I want to display set of images in horizontal viewpager .I have used the Universal Image Loader Everything is fine.But after zooming, quality of images have lost even for b
Universal Image Loader keeps reduced images in memory to save memory. Size of every reduced image is calculated and it depends on target ImageView for this image (android:layout_width
, android:layout_height
, android:maxWidth
, android:maxHeight
parameters, android:scaleType
, device screen size are considered).
By default maximum target size for every image is device's screen size. So you have images of size similar to device screen size and when you zooming you see bad quality.
So you should load in ImageView full-sized images (for zooming support without quality loss). Set your own maximum size for cached images in memory:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.memoryCacheExtraOptions(1200, 1000) // maximum width and height of your images
...
.build();
In this case you will load large Bitmaps in memory so I recommend not to cache them in memory. Disable memory caching for these images (don't call .cachenMemory()
in DisplayImageOptions) and set .imageScaleType(ImageScaleType.EXACT)
. You can disable them globally (in .defaultDisplayImageOptions(...)
) or for every display task (imageLoader.displayImage(...)
)
TO PREVENT OOM:
.cachenMemory()
in DisplayImageOptions).imageScaleType(ImageScaleType.EXACT)
.threadPoolSize(1)
(as last try)Recycle Bitmaps in adapter:
private class ImagePagerAdapter extends PagerAdapter {
...
@Override
public void destroyItem(View container, int position, Object object) {
View view = (View) object;
((ViewPager) container).removeView(view);
ImageView imageView = (ImageView) view.findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
if (bd != null) {
Bitmap bmp = bd.getBitmap();
if (bmp != null) {
bmp.recycle();
}
}
}
...
}