How to store Android Bitmap into SQLite and remove it without loss

Source: Internet
Author: User

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 ();}

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.