Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中以文本形式发送图像_Java_Image_Character Encoding_Java Io - Fatal编程技术网

在java中以文本形式发送图像

在java中以文本形式发送图像,java,image,character-encoding,java-io,Java,Image,Character Encoding,Java Io,是否可以将图像读取为文本并通过网络发送?是的,那么我们怎么做呢?您可以对图像进行base64编码以生成(文本)字符串。 您可以轻松使用: import org.apache.commons.codec.binary.Base64; // Read the byte array from file, DB, etc byte[] imageByteArray = getImageByteArray(); String base64Image = Base64.encodeBase64Strin

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

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

您可以轻松使用:

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

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

String base64Image = Base64.encodeBase64String(imageByteArray);

你能提供一些关于用例的背景信息吗:图像的来源(文件/生成)。什么样的进程在发送图像,哪个传输,谁在接收图像(其他程序,其他java程序,web浏览器等等)?我不喜欢Apache commons的Base64,因为它包含一些繁琐的API,比如
byte[]encodeBase64(byte[])
。在这种情况下,OP最终使用了其中一种,并出现了以下问题: