如何存储和检索机器人在SQLite数据库图片? [英] How to store and retrieve images in sqlite database in android?

查看:134
本文介绍了如何存储和检索机器人在SQLite数据库图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的测验应用并我需要显示的使用图片一起的问题。我在SQLite数据库的存储问题 Android中显示它们。但我不知道如何将图像存储在sqlite的分贝,并显示它们。
    我经历了这么多的链接去发现如何显示来自远程数据库的图像。但我的需要从本地的SQLite数据库显示图像。我怎样才能做到这一点。请帮我对此。

I am working on quiz application and I need to display questions along with images. I have stored the questions in sqlite database and displaying them in android. But I dont know how to store the images in sqlite db and display them. I have gone through so many links and found how to display an image from remote db. But I need to display images from local sqlite db. How can I do that. Please help me regarding this.

先谢谢了。

推荐答案

您一般不二进制数据保存到数据库中。它被认为不好的形式,可以使数据库查询利用,因为数据最终得到存储在磁盘上的路很长。你应该做的是一个文件路径存储在数据库中的图像和图像存储在SD卡中。

You generally don't save binary data to a database. It's considered bad form and can make queries to the database take really long because of the way the data ends up getting stored on the disk. What you should do is store a file path to the image in your database and store the image on the sdcard.

无需编写code的大量对你来说,这里是一个高层次的例子。首先,创建表的图像存储与下面的SQL调用:

Without writing massive amounts of code for you, here's a high-level example. First, create your table to store the image with the following sql call:

CREATE TABLE images (_id INTEGER PRIMARY KEY AUTOICREMENT, file_path TEXT, name TEXT);

当谈到时间,插入你必须做两件事情的图像。首先,写出图像到SD卡。按照说明在这里做到这一点。一旦你已经写了出来,并为它得到一个文件名,你只是做一个SQL查询,像这样:

When it comes time to insert an image you have to do two things. First, write the image out to the SD card. Follow the instructions here to do that. Once you've written it out and gotten a file name for it, you just do a sql query like so:

INSERT INTO images (file_path, name) VALUES ("your file path", "name of image");

当你实际需要来显示图像,您刚刚从你的SD卡读取FILE_PATH指定的文件。

Whenever you actually need to display the image, you just read the file specified by file_path from your sdcard.

这篇关于如何存储和检索机器人在SQLite数据库图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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