从android通用图像加载器下载图像流 [英] Download Image stream from android universal image loader

查看:16
本文介绍了从android通用图像加载器下载图像流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 monodroid 中为我的 Android 应用使用了 android 通用图像加载器.

I use android universal image loader in monodroid for my android app.

有时我需要将一些图像保存在 sdcard 中.在这种情况下,我需要以流形式下载图像,然后将它们保存到 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 显示来自 SD 卡的图像,您应该传递如下 URL:file:///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

即使用 file:// 前缀.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆