Base64 Encoding
Hi,
I know this might be a cake walk for most of u.. but been having quite some trouble here.
How do I decode a base64 encoded image, which is of String format and display it on the jsp screen ?
I can send also acrosss the base 64 encoded image to some one through email.
PLs some one help me out.
Regards
IronKnight
# 1
There's an open source Base64 library here, with examples.
http://iharder.sourceforge.net/current/java/base64/
When you decode a Base64 encoded image, you will end up with something like a bytearray, or a binary inputstream.
How you interpret that, is up to the format of your image.
But a quick look at ImageIcon shows that it accepts a bytearray, without you having to specify a format. It accepts GIF or JPEG.
regards,
Owen
byte[] encoded = null;
// TODO : read in your base64 encoded data, and store in "encoded"
byte[] decoded = Base64.decode(encoded, 0, encoded.length);
ImageIcon myImage = new ImageIcon (decoded)
Image finalImage = myImage.getImage();