Conversion between Android bitmap and base64

Source: Internet
Author: User

Implement handwritten images, convert pictures to strings, and convert strings to pictures to reduce the size of sending content
<pre name= "code" class= "java" >/** * bitmap to Base64 * @param bitmap * @return */public static String bitmapToBase64 (B Itmap bitmap) {String result = null; Bytearrayoutputstream BAOs = null;try {if (bitmap! = null) {BAOs = new Bytearrayoutputstream (); Bitmap.compress (bitmap.com Pressformat.jpeg, BAOs); Baos.flush (); Baos.close (); byte[] bitmapbytes = Baos.tobytearray (); result = Base64.encodetostring (Bitmapbytes, Base64.default);}} catch (IOException e) {e.printstacktrace ();} finally {try {if (BAOs! = null) {Baos.flush (); Baos.close ()}} catch (Ioexcept Ion e) {e.printstacktrace ();}} return result;} /** * Base64 to Bitmap * @param base64data * @return */public static Bitmap base64tobitmap (String base64data) {byte[] bytes = Base64.decode (Base64data, Base64.default); return Bitmapfactory.decodebytearray (bytes, 0, bytes.length);}


Conversion between Android bitmap and Base64

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.