1. Bitmap saved to SQLite data format:
Db.execsql ("Create Table Express" (_id INTEGER PRIMARY KEY autoincrement,express_no varchar), Express_name TEXT, Express_img BLOB); ");
2. Bitmap becomes Blob
Contentvalues values = new Contentvalues ();
Final Bytearrayoutputstream os = new Bytearrayoutputstream ();
Bmp.compress (Bitmap.CompressFormat.PNG, MB, OS);
Values.put ("Express_img", Os.tobytearray ());
Values.put ("Express_name", "ZF");
Values.put ("Express_no", "ZF");
Getcontentresolver (). Insert ("Express", values);
3. Read bitmap from SQLite
Byte[] In=cur.getblob (Cur.getcolumnindex ("express_img"));
Bmpout=bitmapfactory.decodebytearray (in,0,in.length);
4, displayed on the ImageView
ImageView ImageView = (ImageView) View.findviewbyid (r.id.img);
Bytearrayinputstream stream = new Bytearrayinputstream (Cur.getblob (Cur.getcolumnindex ("express_img"));
Imageview.setimagedrawable (Drawable.createfromstream (Stream, "img"));
Summarize:
InputStream: As the data cache, how the data is written for other objects to read, the method is read ();
OutputStream: As a data cache, write content to other objects in the future! Its method write ();
Byte[] In=cur.getblob (Cur.getcolumnindex (MyUser.User.BITMAP_VALUES));
This article is from "Late after" blog, please be sure to keep this source http://xiaoshudi.blog.51cto.com/8634670/1547305
Sqllite Image Access