Reputation: 146
Is BLOB is the only data type by which an image can be stored in database.What is the advantage of using BLOB.What about portability in BLOB datatype.Please give tutorial based on image storage.
Upvotes: 0
Views: 1006
Reputation: 68187
Besides storing bytes in a Blob typed column, another way could be to convert the bytes into Base64
string and simply store that string in a Text typed column. And regarding portability, you decide which one's better and you prefer. Personally I like to play with strings rather than bytes :)
To convert image into Base64 string:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
final byte[] byteArray = stream.toByteArray();
final String imgString = Base64.encodeToString(byteArray, Base64.DEFAULT);
To convert Base64 string into image:
byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT);
Bitmap mBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Upvotes: 1
Reputation: 2805
Instead of storing the image you can store the byte array of that image in DB.You can convert that image to byte array & store in db.When u want to retrieve that image you will get the byte array from convert that byte array to bitmap, you will get your image.
http://www.coderanch.com/t/550604/Android/Mobile/Help-insert-retreive-image-database
Upvotes: 0