unknown os platform
how to convert bitmap to base64 string in Android example | Whats-online.info
whats-online-info

how to convert bitmap to base64 string in Android example


how
2017/01/19 / Science and Tutorials

Android Tutorial: Simple code how to convert a bitmap image to a base64 string programmatically. See an example





Android code: how to convert bitmap image to base64 string





First and foremost, we know base64 is a utility for encoding and decoding the Base64 representation of binary data. For our case, we are going to encode our bitmap image to Base64 string as shown in the example below.

public static String encodeFromString(Bitmap bm){         ByteArrayOutputStream baos = new ByteArrayOutputStream();         bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object         byte[] b = baos.toByteArray();         return Base64.encodeToString(b, Base64.DEFAULT);     }

Print out

String encodedImage = encodeFromString(bitmap);

The android function above encodes a bitmap image to Base64 string and returns a string data type which we will later decode it back to bitmap image


For newbies, encoding is a named mapping between sequences of 16-bit Unicode code units and sequences of bytes


Thanks for your time. Like us on facebook, twitter, and Google plus to get the latest tuts updates close to your social network











You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment