1

i want to save image in sql lite with name and status message and also retrieve it.I want to save the image form the imageview which i get from the gallery and also retrieve it image view.I dont know how i save image in database

2 Answers2

0

Convert image to Base64 String and save in database table with columns such as img_name, status, img Checkout Base64 class in android

public static String convertImageToBase64(Bitmap img)
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        img.compress(Bitmap.CompressFormat.JPEG, 90, baos);  
        byte[] byteArrayImage = baos.toByteArray(); 
        return Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
    }

public static Bitmap convertBase64ToImage(String base64)
    {
        byte[] byteArray = Base64.decode(base64, Base64.DEFAULT);
        return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    }

please refer below links for sqlite

http://www.vogella.com/articles/AndroidSQLite/article.html http://developer.android.com/reference/android/database/sqlite/package-summary.html

Siddhesh
  • 1,370
  • 11
  • 28
0

Insert an image into SQLite database, you need to use BLOB type

See this link :

http://tttrung43.wordpress.com/2012/04/12/store-image-in-sqlite-database/

http://xjaphx.wordpress.com/2011/06/25/insert-image-to-database/

Anand
  • 2,875
  • 1
  • 18
  • 16