Friday, March 13, 2015

How to encode base64 Strings from Bitmaps in Android (JAVA)

This is a relatively easy process. See the function below. It takes a Bitmap variable and outputs a string. 

private static String endcodeBase64 (Bitmap ico) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ico.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);

No comments:

Post a Comment