Jay Donga
Jay Donga

Reputation: 380

How to save image to sqlite database selected from gallery or captured from camera to sqlite database

I want to store image to sqlite database using blob selected from gallery or captured from camera and get back thease images from database to display in listview or gridview.

Upvotes: 1

Views: 2287

Answers (1)

moDev
moDev

Reputation: 5258

It's possible to store image and retrieve image from sqlite database.

code to store it

   // Convert your bitmap to byte array

ByteArrayOutputStream out = new ByteArrayOutputStream();

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

byte[] bytes = out.toByteArray();

ContentValues cv = new ContentValues();

cv.put("IMAGE", bytes);

code to retrieve it

    // Use Cursor to retrieve the image

     byte[] bytes = cursor.getBlob(column_index);

     ByteArrayInputStream input = new ByteArrayInputStream(bytes);

     Bitmap bit = BitmapFactory.decodeStream(input);

Upvotes: 3

Related Questions