0

We have an image in B64, an we want to use that image as loading image in Universal Image Loader while a better image isn't loaded from an url. So we create a bitmap from that url in b64 and convert it into a BitmapDrawable. The result is shown fine if I do:

imageView.setImageDrawable(bitmapDrawable)

But, on DisplayImageOptions, if I set that bitmapDrawable as image on loading, the image is never shown. I'm doing the following:

final DisplayImageOptions imageOptions = mDisplayImageOptionsDefaultBuilder.
        .showImageOnLoading(bitmapDrawable)
        .showImageOnFail(bitmapDrawable)
        .showImageForEmptyUri(bitmapDrawable)
        .build()

As you can see, I am setting the bitmap drawable not only as image when loading, but as image when fails too (as we don't want that image to change in case of error while loading the better image from an url). The result of that is that the bitmap drawable is never shown. What are we doing wrong?

UPDATE: After debugging what was happening I've seen that the problem is not the bitmap drawable, it is supported and working fine. The problem was that I am using a default display options builder (mDisplayImageOptionsDefaultBuilder), than at some point did:

final DisplayImageOptions imageOptions = mDisplayImageOptionsDefaultBuilder.
        .showImageOnLoading(loadingResource)
        .showImageOnFail(errorResource)
        .showImageForEmptyUri(errorResource)
        .build()

So there's a bug in Universal Image Loader, because now I'm creating a display image options with:

.showImageOnLoading(bitmapDrawable)

Another "solution" is do:

final DisplayImageOptions imageOptions = mDisplayImageOptionsDefaultBuilder.
        .showImageOnLoading(0)
        .showImageOnLoading(loadingResource)
        .showImageOnFail(errorResource)
        .showImageForEmptyUri(errorResource)
        .build()

But internally it stores that there's a resource stored, so my drawable is not shown but the stored resource instead. Creating a new DisplayImageOptionsBuilder worked for me, but it would be nice that if the showImageOnLoading is set with a drawable, then the old resource was automatically cleared.

Thanks in advance.

FVod
  • 2,245
  • 5
  • 25
  • 52
  • Is Bitmap supported by UIL ?? – Vivek Mishra Jan 21 '16 at 08:02
  • I think it is not, but drawable is. That's the reason why we are converting the bitmap into a bitmap drawable, so it should be supported (as imageview.setImageDrawable is successfully showing the bitmapDrawable) – FVod Jan 21 '16 at 08:04
  • It's still a bitmap and imageView is Android's part which supports BitmapDrawable – Vivek Mishra Jan 21 '16 at 08:17
  • do you use: Drawable d = new BitmapDrawable(context.getResources(), icon); for convert? – sajad zohrei Jan 21 '16 at 08:23
  • Yes, I'm doing that. I have updated the post. The bitmap drawable is working fine, the issue is that the DisplayImageOptions is using an old image resource, instead of my new value. – FVod Jan 21 '16 at 08:31

2 Answers2

0

UIL only supports the following schemes:

"h t t p://site.com/image.png" // from Web
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)

Use these schemes.

Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
  • I do not understand, so a drawable generated from a bitmap is not supported but a drawable from resources is? – FVod Jan 21 '16 at 08:16
  • Resource drawables are supported – Mustansar Saeed Jan 21 '16 at 08:19
  • Thank you. I have updated the post, the bitmap drawable is supported, the problem is that UIL is using an old loading resource instead of using the bitmap drawable. – FVod Jan 21 '16 at 08:31
0

Universal Image Loader also provide to use the Background functionality.Please check the below coed for it:-

Here Uri is the path of the folder image OR the URL of the image.

imageLoader.loadImage(YOUR_URL, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
   super.onLoadingComplete(imageUri, view, loadedImage);
   layout.setBackgroundDrawable(new BitmapDrawable(loadedImage));
  }
});
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103