Georgia Ingham Georgia is a Java Developer. She has spoken at lots of conferences. Her hobbies include reading, completing puzzle books and cycling.

How to write out BMP images in Java

57 sec read

Previously, we have written about how to read BMP files as images in Java. This time around we wanted to highlight how you can write out BMP images in Java.

What is a BMP file?

BMP ImageA BMP is an image file format, commonly known as a bitmap image, with the extension .bmp or .dib. It was originally created by Microsoft for computers running Windows, and it specifies the color of the pixels in a way that allows them to be displayed on any device.

There are two different ways you can write out BMP files in Java. One way is to use ImageIO. You can also use our JDeli image library. Because JDeli can read and write BMP and many other image file formats, it can provide a complete BMP converter and ImageIO replacement for Java Developers.

ImageIO

ImageIO.write(bufferedImage, "BMP", new File("/path/to/outputFile.bmp"));

Javadoc  (included in JDK)

JDeli

You can easily replace ImageIO (and get much better support for BMP files) by just changing ImageIO.write to JDeli.write.

//Write Image (can also be OutputStream)
File myNewBmpFile=new File("ImageAsBmp.bmp");
JDeli.write(myBufferedImage, "bmp", myNewBmpFile);

Or you can use the JDeli BmpEncoder directly:

BmpEncoder encoder = new BmpEncoder();
encoder.write(bufferedImage, outputStream);
 

Javadoc and Download

The JDeli library supports Bilevel, Grayscale and RGB images.

JDeli can read and write a very wide range of other image formats. Here is the full list on Image file conversions supported.

If you found this guide useful, you can find more image tutorials in our how to series on how to read and write various Image formats.

 

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Georgia Ingham Georgia is a Java Developer. She has spoken at lots of conferences. Her hobbies include reading, completing puzzle books and cycling.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.