user915003 user915003 - 1 year ago 156
Android Question

Android Universal Image Loader URI from InputStream

i want to ask about UIL which the URI input from InputStream. Because my image source from ZIP and then i must extract it to show that image. Because the image is too big, i must use the UIL library, anybody know how to insert UIL from InputStream.

Answer Source

I think you can do it similar to loading images from DB - Can Universal image loader for android work with images from sqlite db?

Lets choose own scheme so our URIs will look like "stream://...".

Then implement ImageDownloader. We should catch URIs with our scheme and return image stream.

public class StreamImageDownloader extends BaseImageDownloader {

    private static final String SCHEME_STREAM = "stream";
    private static final String STREAM_URI_PREFIX = SCHEME_STREAM + "://";

    public StreamImageDownloader(Context context) {

    protected InputStream getStreamFromOtherSource(String imageUri, Object extra) throws IOException {
        if (imageUri.startsWith(STREAM_URI_PREFIX)) {
            return (InputStream) extra;
        } else {
            return super.getStreamFromOtherSource(imageUri, extra);

Then we set this `ImageDownloader into configuration:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .imageDownloader(new StreamImageDownloader(context))


And then we can do following to display image from DB:

ImageStream is = ...; // You have image stream
// You should generate some unique string ID for this stream
// Streams for the same images should have the same string ID
String imageId = "stream://" + is.hashCode();

DisplayImageOptions options = new DisplayImageOptions.Builder()

imageLoader.displayImage(imageId, imageView, options);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download