0
public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
{
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    image.compress(compressFormat, quality, byteArrayOS);
    return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
}

above code is to convert image to base64 string, but i want to convert image to base64 binary, and the conversion output of base64 binary will be look like "[255,216,255,224,0,16,74,70,73,70,0,1,1,1,0,96,0,96,0,0,255,219,0,67,0,8,6,6,7,6,5,8,7,7,7,9,9,8,10,12,20,13,12,11,11,12,25,18,19,15,20,29,26,31,30,29,26,28,28,32,36,46,39,32,34,44,35,28,28,40,55,41,44,48,49,52,52,52,31,39,57,61,56,50,60,46,51,52,50,255,219,0,67,1,9,9,9,12,11,12,24,13,13,24,50,33,28,33,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,.................,253,246,255,0,190,141,20,80,2,249,142,57,222,223,153,160,200,231,146,237,159,173,20,80,1,230,63,247,219,254,250,52,155,223,251,237,255,0,125,26,40,160,4,103,102,108,177,44,79,82,78,73,162,138,40,3,255,217] ".. can anyone help me? thanks in advance.

gaurang
  • 2,217
  • 2
  • 22
  • 44

3 Answers3

1

In your first step you are encoding it to Base64. To get binary data is to decode it back. :) You can do it like below

byte[] byteArr = Base64.decode("Pass BASE64 String here", Base64.DEFAULT);
SripadRaj
  • 1,687
  • 2
  • 22
  • 33
0

see this answer

Java - Convert image to Base64

In this post user is writing data in a file and then reading it from there using Apache Commons IOUtils here:

 Base64.encode(FileUtils.readFileToByteArray(file));

also a limit of array is also specified to capture encoded byte array.

byte[] byteArray = new byte[102400];
 base64String = Base64.encode(byteArray);
Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95
0
Bitmap to Base64 (Java)
private String bitmapToBase64(Bitmap bitmap)
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
teja
  • 93
  • 2
  • 11