Store and restore blob from sqlite database for android

I need to know to determine the blob data type in eclipse. I am developing an Android application and I want to save the image and record in the database. I know that you need to use blob as a data type. My question is how to define it in the DBhandler class and class. Can anyone help me with the codes.

+1
android eclipse database image recording
Jul 26 2018-12-12T00:
source share
1 answer

Blob is used to store an array of bytes in sqlite.

To convert a bitmap to an array of bytes, use the following code:

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.thumbnail); ByteArrayOutputStream out = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, out); byte[] buffer=out.toByteArray(); 

To save an array of bytes in blob, use the following code:

  ContentValues cv=new ContentValues(); cv.put(CHUNK, buffer); //CHUNK blob type field of your table long rawId=database.insert(TABLE, null, cv); //TABLE table name 

Read more about blob using the link

+5
Jul 26 '12 at 4:45
source share



All Articles