Android:从SQLite显示图像



我正在学习android中的数据库,遇到了以下问题,我想检索一个图像,如何将下面的代码改为image而不是string?

public List<String> getImage(){
    List<String> listRows = new ArrayList<String>();
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor c;
    try {
        c = db.rawQuery("SELECT image FROM " + MY_TABLE + " WHERE _id = "  + _id, null);
        if(c == null) return null;
        String row;
        c.moveToFirst();
        do {            
            row = c.getString(0);            
            listRows.add(row);
        } while (c.moveToNext()); 
        c.close();
    }
    catch (Exception e) {
        Log.e("LOGmsg getDBImage", e.getMessage());
    }
    db.close();        
    return listRows;
}   

将图像存储在数据库中是一种糟糕的做法,最好将图片存储在sd上,并将其存储在数据库路径

将图像视为字节数组,并将其作为Blob对象写入数据库/从数据库中检索。

最新更新