我就联系该做一个项目,我需要导入/存储照片SQLite中DataBase.From我看过,我必须将图片转换成不同的格式(在这种假设可能是错误的),然后存储它在数据库中。你能告诉我我该怎么做,或者我可以用不同的方法来做到这一点?两者都会对我有所帮助,这样我就可以学到更多。如何从SQLite数据库导入图片?
谢谢你,
我就联系该做一个项目,我需要导入/存储照片SQLite中DataBase.From我看过,我必须将图片转换成不同的格式(在这种假设可能是错误的),然后存储它在数据库中。你能告诉我我该怎么做,或者我可以用不同的方法来做到这一点?两者都会对我有所帮助,这样我就可以学到更多。如何从SQLite数据库导入图片?
谢谢你,
根据你想从画面,无论是从网络或从SD卡。不过,我假设你可以得到它并将其转换为位图。在数据库
Bitmap bm = (get it from anywhere);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
//the below line is used if you like to scale it down to store it into the database
bm = Bitmap.createScaledBitmap(bm, width, height, false);
//then put it into a byte array to store it in the database
bm.compress(CompressFormat.JPEG, 100, blob);
// method call to database
dbClass.addPicture(blob.toByteArray());
表的定义:在数据库类
SQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS Pictures (id integer primary key autoincrement, pic blob not null ");
AddPicture方法是以下
public void addPicture(byte[] picture){
db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("pic", picture);
db.insert("Pictures ", null, cv);
}
我希望帮助
存储图片为BLOB 。您可以存储您希望的任何格式。 – 2012-08-12 01:40:59
我很抱歉,对于android来说很新,我不知道blob是什么? – 2012-08-12 02:57:17
你并不需要了解Android的东西,但看了祝福[SQLite的文档(http://www.sqlite.org/docs.html)你去询问这类问题之前。 – 2012-08-12 21:05:05