Android Universal Image Loader URI from InputStream
Asked Answered
S

2

5

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.

Seeress answered 14/2, 2014 at 1:18 Comment(1)
Pass absolute path of the image to show it.Timmy
C
6

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) {
        super(context);
    }

    @Override
    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))
    .build();

ImageLoader.getInstance().init(config);

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()
    ...
    .extraForDownloader(is)
    .build();

imageLoader.displayImage(imageId, imageView, options);
Crossrefer answered 16/2, 2014 at 9:34 Comment(1)
Hi @NOSTRA, Implementing your answer i faced this problem (#39654779). Do you have any idea about this?Concertize
T
1

Acceptable paths

String imageUri = "http://someurl.com/image.png"; // from Web
String imageUri = "file:///mnt/sdcard/image.png"; // from SD card
String imageUri = "content://media/external/audio/albumart/13"; // from content provider
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)

Then show the image

imageLoader.displayImage(imageUri, imageView);

from documentation: https://github.com/nostra13/Android-Universal-Image-Loader

Timmy answered 14/2, 2014 at 1:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.