android操作sqlite3的blob字段,显示数据中的图片

SQLiteDatabase database = SQLiteDatabase
        .openOrCreateDatabase(getFileStreamPath(fileName)
                .getAbsolutePath(), null);
Cursor cursor = database.rawQuery(
        "select name,image from users", new String[] {});

if (cursor.moveToFirst()) {
    userName = cursor.getString(0);
    ByteArrayInputStream stream = new ByteArrayInputStream(
            cursor.getBlob(1));
    image = Drawable.createFromStream(stream, "image");
    Log.i(TAG, "user name: " + userName);
}
database.close();

 

声明的成员变量,供上面代码使用的:

private String userName;

private Drawable image;

 

在对话框里面显示:

AlertDialog.Builder builder = new Builder(
        WelComeMainActivity.this);
builder.setMessage("数据更新完毕。用户名:" + userName);
builder.setTitle("提示");
builder.setIcon(image);
builder.setPositiveButton("确认", new OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog,
            int which) {
        dialog.dismiss();
    }
});
builder.create().show();

你可能感兴趣的:(android,Stream,image,String,sqlite,dialog)