how do you encode and decode images in java?
I have this following scenario, I want to enco开发者_StackOverflowde an image for example(abc.gif) in any format (bytes, base64). Then Send it over a SOAP message and decode the image and save the image in a folder on another computer.
I am exposing this as a web service. I am using TIBCO designer to invoke this web service of encoding of images.
Any way to do the java encoding of images?
You can create an Image
from an array of bytes with Toolkit.createImage
. To encode an image you could use an ImageWriter
. In general, the complete javax.imageio
package can probably help you a lot.
If you're looking for libraries to do Base64 or similar encoding/decoding, then I would say 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).
精彩评论