1. Bitmap saved to SQLite data format:
Java code
- Db.execsql ("Create table Express" (_id INTEGER PRIMARY KEY autoincrement,express_no varchar), Express_name TEXT, Express_img BLOB); ");
2. Bitmap becomes Blob
Java code
- 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
Java code
- Byte[] In=cur.getblob (Cur.getcolumnindex ("express_img"));
- Bmpout=bitmapfactory.decodebytearray (in,0,in.length);
displayed on the ImageView
Java 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"));
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 ();
Java code
- Byte[] In=cur.getblob (Cur.getcolumnindex (MyUser.User.BITMAP_VALUES));
This also initializes the data, where byte is the base type and does not require a length definition.
Android save picture to SQLite, read the picture in SQLite