I need to know to define blob data type in eclipse. I am developing an app for android and i want to save image and a recording in database. I know have to use blob as the data type. My question is how do i define it in the class and the DBhandler class. Can someone provide me help with codes.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Blob is used to save byte array in sqlite.
To convert a bitmap to byte array use 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 a byte array in blob type use 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 by this link