Zain Zain is a Java developer. His is a knowledge seeker who likes to try out and explore new things.

How to read BMP images in Java

56 sec read

In this article, I will be writing about BMP images and how to read them in Java.

What is BMP?

A BMP, bitmBMP Imageap image file, is a file format which stores images. It supports 2d images in monochrome (one colour) and colour. The BMP file format supports 2 file extensions including .bmp and .dib (Device Independant Bitmap). It was primarily designed for Window platforms although it also works on other platforms.

BMP images are popular and can be read by JDeli, ImageIO and JAI. JDeli can read and write a very wide range of image formats. Here is the full list on Image file conversions supported.

How to read BMP images in Java?

Here are examples of how BMP images can be read in Java.

ImageIO:

File bmpFile = new File("bmpImage.bmp");
BufferedImage image = ImageIO.read(bmpFile);

You can find the javadocs for ImageIO here. You can find more information on ImageIO (included with the JDK) on their main page.

JAI:

 RenderedImage image = JAI.create("fileload", "test1.bmp");

You can find the javadocs for JAI here. More information on JAI can be found here.

JDeli:

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

//Read Image (can also be OutputStream or byte array)
File bmpFile = new File("bmpImage.bmp"); 
BufferedImage image = JDeli.read(bmpFile);

Or you can use the JDeli BmpDecoder directly:

BmpDecoder decoder = new BmpDecoder();
BufferedImage image = decoder.read(rawImageBytes);

JDeli can provide a complete BMP converter and ImageIO replacement for Java Developers. You can find more information on the JDeli sales page.

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.

Zain Zain is a Java developer. His is a knowledge seeker who likes to try out and explore new things.

How to choose JPG versus JPEG2000 for image files

Since we started to support both JPG and JPG2000 as image file outputs in our software, we have found that this is a very...
Mark Stephens
1 min read

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.