user1688181
user1688181

Reputation: 494

Improve the Volley NetworkImageView image quality?

I'm Using Volley NetworkImageView to load image from web.following method is to get ImageLoader.

 public  static ImageLoader getVolleyImageLoader(RequestQueue queue){

        ImageLoader imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(5);
                public void putBitmap(String url, Bitmap bitmap) {
                    mCache.put(url, bitmap);
                }
                public Bitmap getBitmap(String url) {
                    return mCache.get(url);
                }
            });

    return imageLoader;

    }

this is layout widget

  <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/deal_thumb_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="@dimen/deals_image_left_margin" />

this is working fine.load image successfully. but the quality of the image is bad.size of the image is too small than the actual image.

How can I improve the quality of the image?

Upvotes: 2

Views: 555

Answers (1)

M. Bichon
M. Bichon

Reputation: 3

You have to include the volley source code into your project (as suggested in the Google IO 2014 Video)

Then open ImageLoader from the toolbox folder and change the configuration of the bitmap returning by the ImageRequest :

protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}

Just change the Config.RGB_565 by Config.ARGB_8888 and you're done

Upvotes: 0

Related Questions