1

In my Application, I need to convert Image to Base64 format. Could anyone please let me know how can I do that?

Please forward your valuable suggestions.

Thanks in advance :)

Melquiades
  • 8,496
  • 1
  • 31
  • 46
Remmyabhavan
  • 1,689
  • 5
  • 36
  • 65

3 Answers3

1

Android has a class for doing this.

http://developer.android.com/reference/android/util/Base64.html

Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161
0

You can use the Base64 Android class:

String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);

You'll have to convert your image into a byte array though. Here's an example:

Bitmap bm = BitmapFactory.decodeFile("/path/to/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object   
byte[] b = baos.toByteArray(); 
Melquiades
  • 8,496
  • 1
  • 31
  • 46
sravan
  • 5,303
  • 1
  • 31
  • 33
0

This question has already been asked before..

You can try using this class to encode or decode base64 String

http://www.source-code.biz/base64coder/java/

DeRagan
  • 22,827
  • 6
  • 41
  • 50