The conversion of Android bitmap and Base64 strings

Source: Internet
Author: User
Tags base64

Can bitmap picture and Base64 string to convert to each other ~ henceforth mother no longer have to worry about me to deal with bitmap ~

/**

* Convert Bitmap to Base64 string

*

* @param bitmap

* @return Base64 string

*/

Public String bitmaptostring (Bitmap Bitmap, int bitmapquality) {

Convert Bitmap to String

string string = null;

Bytearrayoutputstream Bstream = new Bytearrayoutputstream ();

Bitmap.compress (Compressformat.png, bitmapquality, Bstream);

byte[] bytes = Bstream.tobytearray ();

String = base64.encodetostring (bytes, base64.default);

return string;

}

/**

* Convert base64 to bitmap picture

*

* @param string Base64 strings

* @return Bitmap

*/

Public Bitmap Stringtobitmap (string string) {

Converts a string to a bitmap type

Bitmap Bitmap = null;

try {

Byte[] Bitmaparray;

Bitmaparray = Base64.decode (string, base64.default);

Bitmap = Bitmapfactory.decodebytearray (Bitmaparray, 0,

Bitmaparray.length);

catch (Exception e) {

E.printstacktrace ();

}

return bitmap;

}

Related Article

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.