Conversion between android bitmap and base64 strings
Bitmap images and base64 strings can be converted to each other ~ Since then, my mom no longer has to worry about processing bitmap ~
/**
* Convert bitmap to a base64 string
*
* @ Param bitmap
* @ Return base64 string
*/
Public String bitmaptoString (Bitmap bitmap, int bitmapQuality ){
// Convert Bitmap into a 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 image
*
* @ Param string base64 string
* @ Return bitmap
*/
Public Bitmap stringtoBitmap (String string ){
// Convert the string to the 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;
}