Sylwia Dorota Kedzia Sylwia is a Java developer. She is very passionate about programming and all things Polish.

How to write JPEG Images in Java (Tutorial)

57 sec read

JPG icon

In this article, I will show you how to write JPEG images in Java. We also have a related article covering how to read JPG files in Java.

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

  1. Create a File (or OutputStream) object for the JPEG output.
  2. Pass image, jpg type and File (or OutputStream) object into write method

and the Java code to write JPEG in ImageIO…

File file = new File("/path/to/outputFile.jpg"));
ImageIO.write(bufferedImage, "jpg", file);

ImageIO is able to write images as JPEG files, but it offers very little control over the process or the output. So we added the ability to write out images as JPEG files to our JDeli Image library.

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

  1. Add JDeli to your class or module path. (download trial jar).
  2. Create a File (or OutputStream) object
  3. Pass image, JPEG type and File (or OutputStream) object into write method

and the Java code to write JPEG in JDeli…

In below picture, my original file was a .png image, and I used JDeli to write it out as a .jpg image.

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



Are you a Java Developer working with Image files?

Why do developers choose JDeli over free alternatives?

  1. Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
  2. Better support than alternatives for JPEG, PNG, TIFF.
  3. Prevent JVM crashes caused by native code in other image libraries
  4. Better performance than other popular Java image libraries
Sylwia Dorota Kedzia Sylwia is a Java developer. She is very passionate about programming and all things Polish.