从sqllite数据库存储和修复blob for android

use*_*456 1 database eclipse android image recording

我需要知道在eclipse中定义blob数据类型.我正在为Android开发一个应用程序,我想在数据库中保存图像和记录.我知道必须使用blob作为数据类型.我的问题是如何在类和DBhandler类中定义它.有人可以帮我提供代码帮助.

jee*_*eet 6

Blob用于在sqlite中保存字节数组.

要将位图转换为字节数组,请使用以下代码:

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.thumbnail);

ByteArrayOutputStream out = new ByteArrayOutputStream();

image.compress(Bitmap.CompressFormat.PNG, 100, out);

byte[] buffer=out.toByteArray();
Run Code Online (Sandbox Code Playgroud)

要在blob类型中保存字节数组,请使用以下代码:

   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
Run Code Online (Sandbox Code Playgroud)

通过此链接了解有关Blob的更多信息