Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Bitmap from universal image loader

I'm trying to get a bitmap resource using the Universal Image Loader Library. I have overridden the onLoadComplete() method like this:

loader.displayImage(thumbnail.get(position), hold.ivThumbnailReflection, options, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingComplete(String urlLink, View arg1, Bitmap loadedImage) {

            Log.i("loading complete","loading complete "+loadedImage);
            hold.ivThumbnail.setImageBitmap(loadedImage);


        }

        @Override
        public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }
    });

The image is set in the ivThumbnailReflection view but there is no image on the ivThumbnail view. When I print the object for loadedImage I get a string in the form- android.graphics.Bitmap@4170f1d0.

What am I doing wrong? Pls help.

Edit: Initialize options for UIL:

options = new DisplayImageOptions.Builder()
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
like image 699
Anirudh Avatar asked Dec 30 '25 17:12

Anirudh


2 Answers

Why don't you use only this instead of using complete :

imageLoader.displayImage(imageUri, imageView);

Or use this

imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() 
{
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
    {
         // Do whatever you want with Bitmap
    }
});
like image 199
Harish Godara Avatar answered Jan 01 '26 06:01

Harish Godara


Try using loadImageSync(String uri) . It gives you bitmap.

If you want drawable from bitmap

Drawable d = new BitmapDrawable(getResources(),imageLoader.loadImageSync(url);
like image 27
Sanjay Kumar Avatar answered Jan 01 '26 08:01

Sanjay Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!