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