Generic URI for Generic Image Loader from InputStream

I want to ask about a UIL that introduces a URI from an InputStream. Because my image source is from ZIP, and then I have to extract it to show this image. Since the image is too large, I have to use the UIL library, does anyone know how to insert a UIL from an InputStream.

+4
source share
2 answers

I think you can do it similar to loading images from a database - Can a universal image downloader for android work with images from sqlite db?

Allows you to choose your own scheme so that our URIs look like "stream: // ..." .

Then we implement ImageDownloader. We need to catch the URI with our scheme and return the stream of images.

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” to the configuration:

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

ImageLoader.getInstance () initialization (configuration);

And then we can do the following to display the image from the database:

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);
+6
source

Allowed 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 the documentation: https://github.com/nostra13/Android-Universal-Image-Loader

+1
source

Source: https://habr.com/ru/post/1526850/


All Articles