0

i'm using universal image loader to populate thumbnails into gridview from assets gallary but images are loading slowly during scrolling up or down so i think because images are being loaded with it's current resolution so how i can change the resolution of the images for example i used to use createScaledBitmap to scale down the bitmap Here is my code :

public class ImageAdapter extends BaseAdapter {
private Context mContext;
private List<String> mList;
private int mheight;
private int mwidth;
private InputStream is;
private HomePage homePage;
private ImageLoader imageLoader;




public ImageAdapter(Context context, List<String> list, int height, int width) {
    mContext = context;
    mList = list;
    mheight = height;
    mwidth = width;
    ImageLoader imageLoader = ImageLoader.getInstance();
    this.imageLoader = imageLoader;

}


@Override
public int getCount() {
    return mList.size();
}

@Override
public Object getItem(int position) {
    return mList.get(position).toString();
}

@Override
public long getItemId(int position) {
    return 0;
}





@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {
        imageView = new ImageView(mContext);
    } else {
        imageView = (ImageView) convertView;
    }


    File cacheDir = new File(Environment.getExternalStorageDirectory(),    "UniversalImageLoader/Cache");
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
   .threadPoolSize(5)
   .memoryCacheExtraOptions(mwidth/3, mwidth/3)
   .threadPriority(Thread.MIN_PRIORITY )
    .memoryCache(new UsingFreqLimitedMemoryCache(5000000)) // You can pass your own memory cache implementation
    .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
    .build();

    imageLoader.init(config);
 //
 //
    //display options
    DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.loading)
    .showImageForEmptyUri(R.drawable.loading)
    .cacheInMemory()
    .cacheOnDisc() 
    .bitmapConfig(Bitmap.Config.RGB_565)
    .imageScaleType(ImageScaleType.EXACTLY)
    .build();

//        // Create configuration for ImageLoader

    String imString = mList.get(position);
    String imageUria = "assets://"+imString;

   imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
   imageView.setLayoutParams(new GridView.LayoutParams(mwidth/3, mwidth/3));
   imageLoader.displayImage(imageUria, imageView ,options );
     return imageView ;

} }

Joseph27
  • 129
  • 3
  • 16
  • That might have to do with the resolution of the image you are downloading form the website itself. I'm not too sure if UniversalImageLoader will let you control that. – Kgrover Mar 25 '13 at 16:04
  • do u think it's the reason for slow loading ? despite of my source is not from website it's from assets – Joseph27 Mar 25 '13 at 16:13
  • Could you initialize the builder and everything (all the settings) within onCreate and only do the imageView functions (the last 3 lines) within getView(...)? Try that. – Kgrover Mar 25 '13 at 16:14
  • tried that maybe a lil abit faster than before but still Stub image(Stub image will be displayed in ImageView during image loading ) lasts for a sec before images get displayed – Joseph27 Mar 25 '13 at 17:04
  • 1
    A _full_ second? It does depend on the image resolution... – Kgrover Mar 25 '13 at 17:17
  • Was this problem resolved? – Kgrover Mar 26 '13 at 02:03

0 Answers0