一、bitmap保存到SQLite 中 数据格式: express
- db.execSQL("Create table express ( _id INTEGER PRIMARY KEY AUTOINCREMENT,express_no varchar(100),express_name TEXT,express_img BLOB );");
二、bitmap 变为 Blob 缓存
- ContentValues values = new ContentValues();
- Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.erweima);
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
- values.put("express_img", os.toByteArray());
- values.put("express_name","zf");
- values.put("express_no","zf");
- getContentResolver().insert("express", values);
三、从SQLite中读取Bitmap spa
- byte[] in=cur.getBlob(cur.getColumnIndex("express_img"));
- bmpout=BitmapFactory.decodeByteArray(in,0,in.length);
显示在ImageView上code
- ImageView imageView = (ImageView) view.findViewById(R.id.img);
- ByteArrayInputStream stream = new ByteArrayInputStream(cur.getBlob(cur.getColumnIndex("express_img")));
- imageView.setImageDrawable(Drawable.createFromStream(stream, "img"));
总结:orm
inputStream: 做为数据缓存,数据写如何供别的对象读取,其方法为read();对象
outputStream:做为数据缓存,未来向别的对象写内容!其方法write();get
- byte[] in=cur.getBlob(cur.getColumnIndex(MyUser.User.BITMAP_VALUES));
//这样也能够对数据进行初始化,byte是基本类型,不须要以前进行长度定义。input