Site iconJava PDF Blog

How to write JPEG Images in Java (Tutorial)

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.