Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending image as text in java

Is it possible to read image as text and send it over network? Is yes, then how can we do this?

like image 586
Ankit Avatar asked Sep 15 '26 01:09

Ankit


1 Answers

You could base64 encode the image to produce a (text) string.

Apache Commons Codec has a Base64 implementation that you can easily use:

import org.apache.commons.codec.binary.Base64;

// Read the byte array from file, DB, etc
byte[] imageByteArray = getImageByteArray();

String base64Image = Base64.encodeBase64String(imageByteArray);
like image 106
Mads Hansen Avatar answered Sep 16 '26 13:09

Mads Hansen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!