Link
Skip to main content

Java BMP Writer

Java’s built-in ImageIO has limited support for writing BMP files and provides little control over encoding quality and format-specific options. JDeli is a 100% Java BMP writer that gives you full encoding control with no dependencies.

Getting started

Add JDeli to your project via Maven or Gradle, or see using JDeli with Java modules.

What is supported

The JDeli BMP writer supports the following features:

Feature Support
RGB32 Yes
ARGB32 Yes
RGB24 yes
RGB565 Yes
RGB555 Yes
GrayScale Yes
Indexed Yes
Alpha Yes
Compression - None Yes
Compression - RLE No
Top-down encoding No
Color masks Yes
Output to file Yes
Output to OutputStream Yes
Output to byte[] Yes
Pure Java implementation Yes

Quick start or to replace in existing code using ImageIO:

The simplest way to write a BMP image is:

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

Or to a byte array:

byte[] bmpData = JDeli.write(bufferedImage, "bmp");

Or to an OutputStream:

JDeli.write(bufferedImage, "bmp", os);

Simple usage

For better type safety, use OutputFormat:

JDeli.write(myBufferedImage, OutputFormat.BMP, outputStreamOrFile);

OutputFormat allows setting of any supported Image Format

Benefits:

  • Compile-time safety
  • Cleaner code
  • Recommended for new applications

Advanced usage: controlling the output

Use bmpEncoderOptions when you need control over encoding behaviour.

final BmpEncoderOptions options = new BmpEncoderOptions();

//set any options in options instance - examples below

//As of the 2025.05 release, you can set the bmp subtype to write out as. For example:
options.setOutputSubtype(BufferedImage.TYPE_USHORT_565_RGB); 

//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);

BmpEncoderOptions allows setting of specific options.

Various image processing operations can be conducted on the image, detailed documentation can be found here.

Performance comparisons:

These figures were generated using jmh (as documented on our blog) with a standard set of images (also documented). They should be easy to replicate if you wish to validate, the code is on GitHub.

The higher the number, the better.
Benchmark results using JMH:
Mode: Throughput Count: 25 Units: ops/s

Benchmark Score Error
Apache 9.981 ± 0.317
ImageIO 5.692 ± 0.126
ImageIO/TwelveMonkeys 14.833 ± 0.744
JDeli 17.223 ± 0.064
ICafe 34.600 ± 0.969

Number of files: 166

Benchmark AVG Size unreadable output AVG SSIM score AVG Similarity
Apache 29.35KB 0 1.0 Identical or virtually identical
ImageIO 35.62KB 30 0.561341 Low similarity (significant differences)
ImageIO/TwelveMonkeys 0.68KB 83 0.233765 Very different
JDeli 29.77KB 0 0.978171 Very similar (high quality)
ICafe 30.77KB 0 0.968417 Very similar (high quality)

Frequently asked questions

Does JDeli produce better BMP encoding than Java ImageIO?

Yes. While ImageIO can write BMP, JDeli gives you full control over encoding options such as compression and quality, and produces more consistent output across platforms.

Does writing or encoding BMP in Java with JDeli require additional libraries?

No. JDeli is a 100% Java library with no dependencies. It runs on any platform where the JVM runs with no additional installation.

What output types does JDeli support for writing BMP?

JDeli can write and encode BMP to a File, OutputStream, or return the encoded data as a byte array.

See also


Why JDeli?

  • Support image formats such as AVIF, HEIC and JPEG XL that are not supported in Java.
  • Process images up to 3x faster than ImageIO and alternative Java image libraries.
  • Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  • Handle JPEG, PNG, TIFF image file formats fully in Java.
  • Keep your Image files secure as JDeli makes no calls to any external system or third party library.

Learn more about JDeli

Start Your Free Trial