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,466
  • 1
  • 29
  • 43
Remmyabhavan
  • 1,681
  • 5
  • 35
  • 64

3 Answers3

1

Android has a class for doing this.

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

Soumya Simanta
  • 11,173
  • 23
  • 101
  • 157
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,466
  • 1
  • 29
  • 43
sravan
  • 5,165
  • 1
  • 30
  • 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,442
  • 6
  • 39
  • 50