存储和retreieve一滴从sqllite数据库为Android [英] Store and retreieve blob from sqllite database for android

查看:202
本文介绍了存储和retreieve一滴从sqllite数据库为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

斑点是用来保存字节数组中的源码。

Blob is used to save byte array in sqlite.

要位图转换为字节数组使用下面的code:

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();

要保存BLOB类型使用的字节数组以下code:

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

了解更多关于一滴本的链接

这篇关于存储和retreieve一滴从sqllite数据库为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆