问题
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 big images.
The Size of image is 1000*1000
I have configured with the following settings
Options options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher)
.cacheOnDisc()
.cacheInMemory()
.imageScaleType(ImageScaleType.POWER_OF_2)
.build();
config = new ImageLoaderConfiguration.Builder(ctx)
.defaultDisplayImageOptions(options)
.build();
ImageLoader.getInstance().init(config);
回答1:
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:
- Disable memory caching for these images (don't call
.cachenMemory()
in DisplayImageOptions) - Set
.imageScaleType(ImageScaleType.EXACT)
- Set
.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(); } } } ... }
来源:https://stackoverflow.com/questions/12634088/blurred-imageview-after-zooming-while-using-universal-image-loader-in-android