Write Base64-encoded image to file

Assuming the image data is already in the format you want, you don’t need ImageIO at all – you just need to write the data to the file:

// Note preferred way of declaring an array variable
byte[] data = Base64.decodeBase64(crntImage);
try (OutputStream stream = new FileOutputStream("c:/decode/abc.bmp")) {
    stream.write(data);
}

(I’m assuming you’re using Java 7 here – if not, you’ll need to write a manual try/finally statement to close the stream.)

If the image data isn’t in the format you want, you’ll need to give more details.

Leave a Comment