3

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

bluish
  • 26,356
  • 27
  • 122
  • 180
Ankit
  • 3,083
  • 7
  • 35
  • 59
  • 3
    could you give some background on the usecase: where the image originates (file/generated). What kind of process is sending the image, which transport, who's receiving it (other program, other java program, a web browser, ...) ? – maasg Jun 26 '11 at 13:17

1 Answers1

5

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);
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • The thing I dislike about Apache commons' Base64 is that it includes some fugly APIs, like `byte[] encodeBase64(byte[])`. In this case, the OP ended up using one of those and having problems: http://stackoverflow.com/questions/6484369/issue-with-base64-encoding-decoding-java – ninjalj Jun 27 '11 at 20:41