Base64 encoding and decoding of Android Images,

Source: Internet
Author: User
Tags printable characters

Base64 encoding and decoding of Android Images,

 

Base64 is one of the most common encoding methods used to transmit 8-bit bytecode on the network. Base64 is a way to represent binary data based on 64 printable characters.

 

Base64 encoding is a process from binary to character. It can be used to transmit long identification information in the HTTP environment. For example, in Java Persistence system Hibernate, Base64 is used to encode a long unique identifier (generally 128-bit UUID) into a string, used as parameters in HTTP forms and http get URLs. In other applications, binary data is often encoded in a URL (including hidden form fields) format. In this case, Base64 encoding is not readable and must be decoded before reading.

 

I. Encoding

Public void encodeImage (Bitmap bitmap) {ByteArrayOutputStream baos = new ByteArrayOutputStream (); // read the image to ByteArrayOutputStream bitmap. compress (Bitmap. compressFormat. PNG, 40, baos); // If the parameter is 100, bytes [] bytes = baos will not be compressed. toByteArray (); String strbm = Base64.encodeToString (bytes, Base64.DEFAULT );}

Strbm is the encoded character.

Ii. Decoding

public void sendImage(String bmMsg){

byte [] input = Base64.decode(bmMsg, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(input, 0, input.length);
 }

 

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.