从Android的通用图像加载器下载图像流 [英] Download Image stream from android universal image loader
问题描述
我采用Android 通用图像装载机的在monodroid我的Android应用程序。
I use android universal image loader in monodroid for my android app.
有一段时间我需要保存一些图像的SD卡。在这种情况下,我需要下载溪流的图像,然后将它们保存到SD卡。
some time i need to save some images in sdcard. In this cases i need to download images in streams and then save them into sdcard.
有没有办法通过数据流与此库下载图像。因为在许多情况下,图像被缓存在库中?
Is there any way to download images by stream with this library. because in many cases the image is cached in the library?
推荐答案
UIL可以缓存在SD卡上的图像(启用缓存在DisplayImageOptions)。您可以定义自己的文件夹中缓存(在ImageLoaderConfiguration)。
UIL can cache image on SD card (enable caching in DisplayImageOptions). You can define your own folder for cache (in ImageLoaderConfiguration).
如果你想使用UIL你应该通过URL如SD卡,显示的图像:
文件:///mnt/sdcard/MyFolder/my_image.png
If you want to display image from SD card using UIL you should pass URL like:
file:///mnt/sdcard/MyFolder/my_image.png
即。使用文件://
preFIX
I.e. use file://
prefix.
UPD: 如果你想保存在SD卡上的图像:
UPD: If you want save image on SD card:
String imageUrl = "...";
File fileForImage = new File("your_path_to_save_image");
InputStream sourceStream;
File cachedImage = ImageLoader.getInstance().getDiscCache().get(imageUrl);
if (cachedImage != null && cachedImage.exists()) { // if image was cached by UIL
sourceStream = new FileInputStream(cachedImage);
} else { // otherwise - download image
ImageDownloader downloader = new BaseImageDownloader(context);
sourceStream = downloader.getStream(imageUrl, null);
}
if (sourceStream != null) {
try {
OutputStream targetStream = new FileOutputStream(fileForImage);
try {
IoUtils.copyStream(sourceStream, targetStream, null);
} finally {
targetStream.close();
}
} finally {
sourceStream.close();
}
}
这篇关于从Android的通用图像加载器下载图像流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!