1、bitmap保存到sqlite 中 数据格式:
2、bitmap 变为 Blob
ContentValuesvalues=newContentValues();@H_403_13@
Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.erweima);@H_403_13@
finalByteArrayOutputStreamos=newByteArrayOutputStream();@H_403_13@
bmp.compress(Bitmap.CompressFormat.PNG,100,os);@H_403_13@
values.put("express_img",os.toByteArray());@H_403_13@
values.put("express_name","zf");@H_403_13@
values.put("express_no",250); line-height:18px"> getContentResolver().insert("express",values);@H_403_13@
3、从sqlite中读取Bitmap
byte[]in=cur.getBlob(cur.getColumnIndex("express_img"));@H_403_13@
bmpout=BitmapFactory.decodeByteArray(in,0)">0,in.length);@H_403_13@
显示在ImageView上
ImageViewimageView=(ImageView)view.findViewById(R.id.img);@H_403_13@
ByteArrayInputStreamstream=newByteArrayInputStream(cur.getBlob(cur.getColumnIndex("express_img")));@H_403_13@
imageView.setImageDrawable(Drawable.createFromStream(stream,"img"));@H_403_13@
总结:
inputStream: 作为数据缓存,数据写如何供别的对象读取,其方法为read();
outputStream:作为数据缓存,将来向别的对象写内容!其方法write();
byte[]in=cur.getBlob(cur.getColumnIndex(MyUser.User.BITMAP_VALUES));@H_403_13@
//这样也可以对数据进行初始化,byte是基本类型,不需要之前进行长度定义。