2

I am using Gallery View in my android application.and all images come from url, so i am using LazyLoader for imageloading in GalleryView. gallery populated completely. but it losts image quality.. i want to populate gallery without image quality lost.. please help me..

Addon_Android
  • 271
  • 1
  • 2
  • 9

1 Answers1

5

If your are talking about Fedor's Lazy Loading, the solution lies in this bit here:

//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
    if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
        break;
    width_tmp/=2;
    height_tmp/=2;
    scale*=2;
}

This is from Line 96 to line 106 here: https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java. I am linking this so that you can check the code from the source and compare with your code.

You will need to change this bit here: final int REQUIRED_SIZE=70. Note that this number needs to the power of 2. With the default of 70, you will get small images and when used in applications which need to display bigger pictures, they will look distorted. Play around with that till you are satisfied with the result.

This should do the trick for you.

Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • 1
    +1. Also, it's pretty simple to modify it such that you can pass the required size value when calling displayImage - this way you can use it for different image-loading needs across the whole app if you need to. I would also like to advertise Nostra's version (it's based on the original by Fedor, I think) https://github.com/nostra13/Android-Universal-Image-Loader as it helped me out quite a lot with my projects. It has a built-in way to easily tweak settings for displaying images – josephus Nov 07 '12 at 11:01
  • Thanx.. i removed while loop only. and problem solved.. :) thanx – Addon_Android Nov 07 '12 at 11:06
  • @JosephusVillarey: I have heard good things about Nostra's Universal Loader too. I have been meaning to give it a shot. But can't play around with the production version. ;-) – Siddharth Lele Nov 07 '12 at 11:09
  • @Addon_Android: Glad to have been of help. :-) – Siddharth Lele Nov 07 '12 at 11:10
  • what happens if I increase the REQUIRED_SIZE? Will there be any problem if I change the REQUIRED_SIZE to 256? Will there be any memory related issues or something else? – Bharath Jan 10 '13 at 14:12
  • @TaruniNeema: Not at all. In fact, I have a setting of 512 and I have never faced any memory issues. – Siddharth Lele Jan 10 '13 at 14:26