How to store Android Bitmap into SQLite and remove it without loss
During the project, ainemo directly saves bitmap to SQLite.
The problem that the image cannot be displayed is caused by the removal of the image.
Then I followed the code to find out. The originally stored data is different from the retrieved data.
Why does this happen?
This is because of the data type used by my project.
(If you change byte [] of the image type to String, the image will become invalid !)
The solution I use is. Encode the byte array into a String before decoding.
Byte [] bitmap_byte = cursor. getBlob (columnIndex); // you can directly retrieve the data that has a transmission problem. BASE64Encoder encode = new BASE64Encoder (); String encode_bitmap = encode is solved through encryption and decoding. encode (bitmap_byte );
Decoding:
String bitemap_string = (String) data. getRow (0 ). getValue (columnName); // decoder BASE64Decoder decode = new BASE64Decoder (); byte [] bitemap_byte = null; try {// bitemap_byte = decode. decodeBuffer (bitemap_string);} catch (IOException e) {Log. e (failed to convert image, getClass (). getName () +); e. printStackTrace ();}