如何检索存储在Sqlite表中的图像?
该表如下所示:
public class ImageInDB extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "test01.db";
private static final String MP_TABLE_NAME = "MPImage";
ImageInDB (Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}// end of
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(" CREATE TABLE " + MP_TABLE_NAME + " ( " +
BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
" img BLOB " +
");" );
}
现在,如何检索图像llok的方法?以下是我的尝试:
public ??? getMP_RPY(long id) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT img FROM MPImage WHERE "+
BaseColumns._ID+" = "+
Long.toString(id), null);
c.moveToFirst();
???? r = c.getDouble(0);
return r;
}
答案 0 :(得分:6)
不要将图像存储到SQLite数据库中。将路径存储到图像中。或者,如果您真的想要将图像存储到数据库中,那么请学习基本的SQ Lite。
答案 1 :(得分:5)
ImageView myImage = (ImageView) findViewById(R.id.myImage);
byte[] bb = cursor.getBlob(cursor.getColumnIndex(MyBaseColumn.MyTable.ImageField));
myImage.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
或强>
请检查this link