0


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); 
jibysthomas
  • 1,601
  • 2
  • 16
  • 24
  • ummm.. what have you tried that didn't work? – Randy Oct 28 '11 at 13:03
  • 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);

    – jibysthomas Oct 28 '11 at 13:07
  • 3
    Please click the "edit" button below the Android tag and put your code in the question. This is not understandable. – Jack Oct 28 '11 at 13:12
  • Possible duplicate: [saving image in the SD card](http://stackoverflow.com/questions/7887078/android-saving-file-to-external-storage/) – RajaReddy PolamReddy Oct 28 '11 at 13:22
  • Possible duplicate: [Image in Db as Blob](http://stackoverflow.com/questions/7516933/how-to-create-a-table-with-a-column-of-type-blob-in-a-dbadapter/) – Venky Oct 28 '11 at 13:21

0 Answers0