在java中将图像作为文本发送

Ank*_*kit 3 java image character-encoding java-io

是否可以将图像作为文本读取并通过网络发送?是的,那我们怎么做呢?

Mad*_*sen 5

您可以对图像进行base64编码以生成(文本)字符串.

Apache Commons Codec有一个可以轻松使用的Base64实现:

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

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

String base64Image = Base64.encodeBase64String(imageByteArray);
Run Code Online (Sandbox Code Playgroud)