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 = ...;
String imageId = "stream://" + is.hashCode();
DisplayImageOptions options = new DisplayImageOptions.Builder()
...
.extraForDownloader(is)
.build();
imageLoader.displayImage(imageId, imageView, options);
source
share