How To Retrieve An Image From A Sqlite Database?
I am storing an image taken from camera into sqlite database can anybody help me to retrieve the same image and i want to show that image in a image view. Here is my Database handl
Solution 1:
To insert Image on database:
Bitmapbitmap= ((BitmapDrawable) image_imgv.getDrawable()).getBitmap();
ByteArrayOutputStreambos4=newByteArrayOutputStream();
bitmap4.compress(Bitmap.CompressFormat.PNG, 100, bos4);
image = bos4.toByteArray();
database = newBBDD(this, "BBDD", null, 1);
SQLiteDatabasedb= database.getWritableDatabase();
ContentValuesreg=newContentValues();
reg.put("img", image);
To retrieve:
database2 = new BBDD(Activity.this, "BBDD", null, 1);
SQLiteDatabase db2 = database2.getReadableDatabase();
if (db2 != null)
{
Cursor cursor = db2.rawQuery("SELECT img FROM database2, null);
if (cursor.moveToFirst())
{
img=cursor.getBlob(cursor.getColumnIndex("img"));
Bitmap b1=BitmapFactory.decodeByteArray(image, 0, image.length);
image_imageview.setImageBitmap(b1);
}
else
Toast.makeText(Activity.this, "Error.", Toast.LENGTH_LONG).show();
db2.close();
}
else
Toast.makeText(sActivity.this, "Error db.", Toast.LENGTH_LONG).show();
}
});
Post a Comment for "How To Retrieve An Image From A Sqlite Database?"