Save Image to SQLite Database in Android

Frequently used code samples and tutorials
Site Admin
Posts: 35
Joined: Tue Nov 18, 2014 2:39 pm

Save Image to SQLite Database in Android

Postby vivekkalady » Fri Nov 21, 2014 4:49 pm

This is a simple example for saving and retrieving image

Setting Up the database

Code: Select all

                   KEY_NAME + " TEXT," +
                   KEY_IMAGE + " BLOB);";

Insert in the Database:

Code: Select all

public void addEntry( String name, byte[] image) throws SQLiteException{
    ContentValues cv = new  ContentValues();
    cv.put(KEY_NAME,    name);
    cv.put(KEY_IMAGE,   image);
    database.insert( DB_TABLE, null, cv );

Retrieving data:

Code: Select all

 byte[] bitmapdata = cursor.getBlob(1);
 Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);

Return to “Tutorials & Examples”

Who is online

Users browsing this forum: No registered users and 1 guest