是否可以将图像作为文本读取并通过网络发送?如果是,那么我们该如何做呢?
是否可以将图像作为文本读取并通过网络发送?如果是,那么我们该如何做呢?
您可以使用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);
byte[] encodeBase64(byte[])
。在这种情况下,楼主最终使用了其中一个API并遇到了问题:http://stackoverflow.com/questions/6484369/issue-with-base64-encoding-decoding-java - ninjalj