I am developing an android app.
i need to save a image from sd card to sqlite database as blob. And later i need to take that image from the database and show it in image view.
The image saves in the sd card as JPG. How can i achieve this.
try {
FileInputStream instream = new FileInputStream(path);
BufferedInputStream bif = new BufferedInputStream(instream);
data = new byte[bif.available()];
}
//write to db
public void cacheImages(byte [] image, String apartId){
SQLiteDatabase db = openDB();
ContentValues cv = new ContentValues();
cv.put("MEDIA", image);
db.insert("CachedListingMedia", null, cv);
db.close(); }
//read from db
byte[] stream = csr.getBlob(0);
Bitmap bm = BitmapFactory.decodeByteArray(stream,0,stream.length);
//write to db public void cacheImages(byte [] image, String apartId){ SQLiteDatabase db = openDB(); ContentValues cv = new ContentValues(); cv.put("MEDIA", image); db.insert("CachedListingMedia", null, cv); db.close(); }
– jibysthomas Oct 28 '11 at 13:07//read from db byte[] stream = csr.getBlob(0); / Bitmap bm = BitmapFactory.decodeByteArray(stream,0,stream.length);