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
Asked
Active
Viewed 1,054 times
2 Answers
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
-
for this i want to make a row in database?? also i want to retrive it in image view?? – murtazamehmood Jan 31 '13 at 07:54
-
do you know how to create table in sqlite? – Siddhesh Jan 31 '13 at 07:55
-
check updated answer and if you got what you want please accept it – Siddhesh Jan 31 '13 at 07:58
-
after converting image to base64 string it is the normal operation of inserting and retrieving... after retriving base64 string you have to convert it to bitmap by doing reverse operation. – Siddhesh Jan 31 '13 at 08:00
-
Thanx boss for your answer – murtazamehmood Jan 31 '13 at 08:04
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