Android Bitmap to Base64 String

Android Bitmap to Base64 String

use following method to convert bitmap to byte array:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();

to encode base64 from byte array use following method

String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

Converting Bitmap to Base64 String in Android

In the call to encodeToString, instead of using the flag Base64.DEFAULT as the second argument, you need to use the flag Base64.NO_WRAP. The default results in conformance with RFC 2045, which produces lines of maximum length 76.



Related Topics



Leave a reply



Submit