在Java中将图像作为文本发送 [英] Sending image as text in java

查看:116
本文介绍了在Java中将图像作为文本发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将图像作为文本读取并通过网络发送?

您可以对图片进行base64编码,以产生一个(文本)图片,



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

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

//从文件,DB等读取字节数组
byte [] imageByteArray = getImageByteArray();

String base64Image = Base64.encodeBase64String(imageByteArray);


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

解决方案

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);

这篇关于在Java中将图像作为文本发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆