Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert an image to a base64 string using Java?

As the title indicates, I want to know how to convert an image to a base64 string in Java. How can I do this?

like image 923
hussain Avatar asked May 06 '10 13:05

hussain


People also ask

Can you Base64 encode an image?

With elmah. io's free image to Base64 encoder, it's easy to copy and paste markup or style for exactly your codebase. Simply drag and drop, upload, or provide an image URL in the controls above and the encoder will quickly generate a Base64 encoded version of that image.


1 Answers

Use the Base64 class.

If you're on pre-Java 8, have a look at one of the following resources:

  • The example at exampledepot.com

  • or Base64Coder - an open-source Base64 encoder/decoder in Java

  • or the Base64 class in the org.apache.commons.codec.binary package

like image 99
aioobe Avatar answered Sep 30 '22 14:09

aioobe