Android Bitmap to Base64 String

Pankaj Singh picture Pankaj Singh · Feb 10, 2012 · Viewed 114.6k times · Source

How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String?

Answer

jeet picture jeet · Feb 10, 2012

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