Created
March 28, 2011 16:34
-
-
Save yeradis/890783 to your computer and use it in GitHub Desktop.
ANDROID - Store and read an image on SQlite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To store an image file inside your SQLite db you should use a Blog field, and due Android SQlite limitations you should store info in this way: | |
ContentValues cv = new ContentValues(); | |
//your table fields goes here | |
... | |
// adding the bitmap in byte array way to the blob field | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
friendInfo.getImage_bmp().compress(Bitmap.CompressFormat.PNG, 100,out); | |
cv.put("avatar_img", out.toByteArray()); | |
db.insert(TABLE_NAME, null, cv); | |
and to read it you can do: | |
byte[] blob = cur.getBlob(cur.getColumnIndex("avatar_img")); | |
Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0,blob.length, opts); | |
friend.setImage_bmp(bmp); | |
friend is an instance from a class, having a Bitmap property called Image_bmp ;) |
how we can retrieve image file from database to imagview
.compress()==> cannot resolve
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provide some example please