可以通用映像加载器与sqlite的分贝的图像机器人的工作? [英] Can Universal image loader for android work with images from sqlite db?

查看:105
本文介绍了可以通用映像加载器与sqlite的分贝的图像机器人的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存我的图片在一个SQLite数据库中的blob-S,也许加密。 是否有可能使用Android的通用映像下载器与图像从SQLite数据库?

I would like to store my images in an sqlite db, in blob-s, and maybe encrypt them. Is it possible to use the Android-Universal-Image-Loader with images from an sqlite database?

推荐答案

UIL不支持从SQLite的DB影像开箱。但是你可以自己添加这种支持,你只需要拿出新的方案/协议的名称(例如分贝:// ),实现自己的 ImageDownloader 并将其设置为配置。

UIL doesn't support of images from SQLite DB out of the box. But you can add this support yourself, you just need come up with new scheme/protocol name (e.g. db://), implement own ImageDownloader and set it to configuration.

例如:

让我们选择自己的计划分贝所以我们的URI看起来像DB:// ......。

Lets choose own scheme db so our URIs will look like "db://...".

然后实现 ImageDownloader 。我们应该抓住的URI与我们的计划,分析它,找到需要的数据在DB和创建的InputStream 它(也可以是 ByteArrayInputStream的)。

Then implement ImageDownloader. We should catch URIs with our scheme, parse it, find needed data in DB and create InputStream for it (it can be ByteArrayInputStream).

public class SqliteImageDownloader extends BaseImageDownloader {

    private static final String SCHEME_DB = "db";
    private static final String DB_URI_PREFIX = SCHEME_DB + "://";

    public SqliteImageDownloader(Context context) {
        super(context);
    }

    @Override
    protected InputStream getStreamFromOtherSource(String imageUri, Object extra) throws IOException {
        if (imageUri.startsWith(DB_URI_PREFIX)) {
            String path = imageUri.substring(DB_URI_PREFIX.length());

            // Your logic to retreive needed data from DB
            byte[] imageData = ...;

            return new ByteArrayInputStream(imageData);
        } else {
            return super.getStreamFromOtherSource(imageUri, extra);
        }
    }
}

然后我们设置这个 ImageLoader的来配置:

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

ImageLoader.getInstance().init(config);

,然后我们可以做以下的从数据库显示的图像:

And then we can do following to display image from DB:

imageLoader.displayImage("db://mytable/13", imageView);

这篇关于可以通用映像加载器与sqlite的分贝的图像机器人的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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