简体   繁体   English

通用图像加载器和BitmapDrawable

[英]Universal Image Loader and BitmapDrawable

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. 我们在B64中有一个图像,我们想将该图像用作Universal Image Loader中的图像,而没有从URL中加载更好的图像。 So we create a bitmap from that url in b64 and convert it into a BitmapDrawable. 因此,我们在b64中从该URL创建了一个位图,并将其转换为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. 但是,在DisplayImageOptions上,如果我在加载时将该bitmapDrawable设置为图像,则该图像将永远不会显示。 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). 如您所见,我不仅将位图可绘制对象设置为加载时的图像,而且还将失败时的图像设置为图像(因为从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: 问题是我使用的是默认显示选项生成器(mDisplayImageOptionsDefaultBuilder),而不是在某些时候:

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: 因此,Universal Image Loader中存在一个错误,因为现在我使用以下方式创建显示图像选项:

.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. 但是在内部它存储有存储的资源,因此未显示我的drawable,而是显示了存储的资源。 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. 创建一个新的DisplayImageOptionsBuilder对我有用,但是如果将showImageOnLoading设置为可绘制对象,则旧资源会自动清除,那就太好了。

Thanks in advance. 提前致谢。

UIL only supports the following schemes: UIL仅支持以下方案:

"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. 使用这些方案。

Universal Image Loader also provide to use the Background functionality.Please check the below coed for it:- Universal Image Loader还提供使用后台功能。请检查以下内容:-

Here Uri is the path of the folder image OR the URL of the image. Uri是文件夹图像的路径或图像的URL。

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));
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM