从变量将图像存储在sqlite中

时间:2017-12-27 10:08:59

标签: android database image sqlite store

我创建了这个数据库

 public void onCreate(SQLiteDatabase db) {
    String query="CREATE TABLE "+tableName+" ( ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
            col1+" INTEGER, "+col2+" String, "+col3+" String, "+col4+" String );";
    db.execSQL(query);
}

在列表中添加一些包含某些信息的图像 我从用户那里得到了图像

public void openGallery(View view){
    Intent open = new Intent(Intent.ACTION_GET_CONTENT);
    open.setType("image/*");
    startActivityForResult(open,100);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode==RESULT_OK && requestCode==100){
        Uri uri = data.getData();
        try {
            InputStream inputStream = getContentResolver().openInputStream(uri);
            Bitmap decodeStream = BitmapFactory.decodeStream(inputStream);
            img.setImageBitmap(decodeStream);
        } catch (FileNotFoundException e) {
            Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
        }

    }



}

我把图像放在变量" img" > img.setImageBitmap(decodeStream);

如何将其保存在数据库库中?

0 个答案:

没有答案