4

hai all i want to store an image in SQLite database.that was selected from SD card.

After searching in the google i found that BLOB is the way to store image in database.

this link followed to insert but it does not work for me, how to convert a image into blob?

how can i store image in the database in blob format?

can anyone give me the sample to store the image in database?

Please help me....

Community
  • 1
  • 1
Abhi
  • 8,935
  • 7
  • 37
  • 60
  • What bit of that "doesn't work for you"? – Blundell Aug 02 '11 at 07:20
  • thank you reply.what about database code?i didnt get the database side code in that link – Abhi Aug 02 '11 at 07:25
  • 2
    At least paste a code example of what you've got so far. That's more likely to get people to help you – Blundell Aug 02 '11 at 07:38
  • sorry, i used same code convert image into byte array, but my question is how to insert image(converted byte array) into database? – Abhi Aug 02 '11 at 07:43
  • it is very easy to deal with image as BLOB just refer this link you wil get to know for sure http://stackoverflow.com/questions/6815355/how-to-store-image-retreived-from-url-in-a-sqlite-database/6815819#6815819 – Mohammed Azharuddin Shaikh Aug 02 '11 at 07:55

1 Answers1

4
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.thumbnail);

ByteArrayOutputStream out = new ByteArrayOutputStream();

image.compress(Bitmap.CompressFormat.PNG, 100, out);

ContentValues cv = new ContentValues();

cv.put(KEY_IMAGE, out.toByteArray());

db.insert(DB_TABLE, null, cv);

A full example http://www.anddev.org/png_image_--und-gt_sqlite_db_--und-gt_imageview-t7188.html

lucasjmatias
  • 123
  • 1
  • 9