简体   繁体   English

用Java编码和解码图像

[英]encode and decode images in java

how do you encode and decode images in java? 您如何在Java中编码和解码图像?

I have this following scenario, I want to encode an image for example(abc.gif) in any format (bytes, base64). 我有以下这种情况,我想以任何格式(字节,base64)对例如image(abc.gif)进行编码。 Then Send it over a SOAP message and decode the image and save the image in a folder on another computer. 然后通过SOAP消息发送它并解码图像,然后将图像保存在另一台计算机上的文件夹中。

I am exposing this as a web service. 我将其作为Web服务公开。 I am using TIBCO designer to invoke this web service of encoding of images. 我正在使用TIBCO Designer调用此图像编码Web服务。

Any way to do the java encoding of images? 有什么办法对图像进行Java编码吗?

You can create an Image from an array of bytes with Toolkit.createImage . 您可以使用Toolkit.createImage从字节数组中创建一个Image To encode an image you could use an ImageWriter . 要编码图像,可以使用ImageWriter In general, the complete javax.imageio package can probably help you a lot. 通常,完整的javax.imageio包可能javax.imageio您有很大帮助。

If you're looking for libraries to do Base64 or similar encoding/decoding, then I would say Apache Commons Codec . 如果您正在寻找执行Base64或类似编码/解码的库,那么我会说Apache Commons Codec At least that's what I've used in the past. 至少那是我过去使用过的。

I'd just transfer the bytes of the image file plus additional information like filename etc. Then you just write the bytes to a new file and you're done. 我只是传输图像文件的字节以及其他信息,如文件名等。然后,您只需将字节写入新文件即可。 It's more like general file streaming, but you might also put some information on the image into the header (where the filename is). 它更像常规文件流,但是您可能还会在图像上将一些信息放入标头(文件名所在的位置)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM