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 BMP images in Java

1 min read

In this article I will show you how to write BMP images in Java.

ImageIO can write out images as BMP files, but it offers very little control over the process or output. So we added the ability to write out images as BMP files to JDeli. In this article we show you how to use either JDeli or ImageIO and cover the benefits of JDeli.

What is a BMP image 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.

 

How to write out an image as a BMP file in ImageIO

Step 1 Create a File (or OutputStream) object

File file = new File("/path/to/outputFile.bmp"));

Step 2 Pass image, BMP type and File (or OutputStream) object into write method

ImageIO.write(bufferedImage, "BMP", file);

Note you can easily switch to JDeli and replace ImageIO by just changing ImageIO.write to JDeli.write.

How to write out an image as a BMP file with JDeli

Step 1 Add JDeli to your class or module path. (download link to the trial jar).

Step 2 Create a File (or OutputStream) object

File file = new File("/path/to/outputFile.bmp"));

Step 3 Pass image, BMP type and File (or OutputStream) object into write method

JDeli.write(bufferedImage, "BMP", file);

In JDeli you can also use a typesafe version

JDeli.write(bufferedImage, OutputFormat.BMP, file);

or pass in a BmpEncoderOptions object for more control over BMP image output.

BmpEncoderOptions options = new BmpEncoderOptions();
JDeli.write(bufferedImage, options, file);

Why use JDeli to write BMP images?

JDeli offers a range of advantages over ImageIO, including:

  • support Bilevel, Grayscale and RGB images.
  • prevent heap related JVM crashes
  • reduce output file size
  • improve write performance
  • supports threading

Learn more about JDeli, or download to try it yourself.

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

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 read HEIC image files in Java with…

In this article, I will explain how to read HEIC files into Java as a BufferedImage. ImageIO does not read HEIC file types so...
Mark Stephens
1 min read

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

Leave a Reply

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

IDRsolutions Ltd 2020. All rights reserved.