将位图保存到数据库中
String query="SELECT * FROM USER_INFO WHERE TRIM(name) = '" + user_name.trim() +"'";
Cursor detail= db.rawQuery(query,null);
if(detail!=null){
detail.moveToFirst();
do{
img=detail.getBlob(2);
s_email=detail.getString(detail.getColumnIndex("email"));
fimg= BitmapFactory.decodeByteArray(img, 0, img.length);
}while(detail.moveToNext());
}
show_email=(TextView) findViewById(R.id.show_email);
show_email.setText("Email:" + s_email);
fetch_image = (ImageView) findViewById(R.id.fetch_image);
fetch_image.setImageBitmap(fimg);
Toast.makeText(this, "Retrive successfully", Toast.LENGTH_SHORT).show();
检索blob并转换为位图,然后在ImageView中显示:
{{1}}
答案 0 :(得分:1)
使用此方法:
public void InsertToDB( String name, String email, byte[] image) throws SQLiteException {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("name", name);
cv.put("email", email);
cv.put("imageCol", image);
database.insert("USER_INFO ", null, cv);
}