In this article, we will show you how to write BMP images in Java. We also have a related article covering how to read BMP files in Java.
ImageIO can write out images as BMP files but has limited control over the process or the output. So we added the ability to write out images as BMP files with JDeli. In this article, we show you how to use either JDeli or ImageIO.
How to write out an image as a BMP file in ImageIO
- Create a File (or OutputStream) object
- Pass image, BMP type and File (or OutputStream) object into write method
and the Java code to write BMP with ImageIO…
File file = new File("/path/to/image.bmp");
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
- Add JDeli to your class or module path. (download link to the trial jar).
- Create a File (or OutputStream) object
- Pass image, BMP type and File (or OutputStream) object into write method
and the Java code to write BMP with JDeli…
File file = new File("/path/to/image.bmp");
ImageIO.write(bufferedImage, "BMP", file);
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
BmpEncoderOptions options = new BmpEncoderOptions();
JDeli.write(bufferedImage, options, file);
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries