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
Selecting Multiple Items in Listview
Get and Parse CSV File in Android
How to Get a Color from Hexadecimal Color String
How to Add a Fragment Inside a Viewpager Using Nested Fragment (Android 4.2)
How to Pass Drawable Between Activities
Quality Problems When Resizing an Image at Runtime
Get Altitude by Longitude and Latitude in Android
Implement Page Curl on Android
Android Textview Padding Between Lines
Update Fragment from Viewpager
Using Gson to Parse a JSON with Dynamic "Key" and "Value" in Android
Adjustpan Not Preventing Keyboard from Covering Edittext
How to Set Entire Application in Portrait Mode Only
Display the Current Time and Date in an Android Application
How to Get String from Different Locales in Android
Android Device Not Shown with Adb
Can Multiple Android Application Access Same Firebase Database