Blurred imageview after zooming while using Universal Image Loader in android

后端 未结 1 2021
无人及你
无人及你 2021-01-01 09:32

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

1条回答
  •  一整个雨季
    2021-01-01 09:48

    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:

    1. Disable memory caching for these images (don't call .cachenMemory() in DisplayImageOptions)
    2. Set .imageScaleType(ImageScaleType.EXACT)
    3. Set .threadPoolSize(1) (as last try)
    4. 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();
                  }
              }
          }
          ...
      }
      

    0 讨论(0)
提交回复
热议问题