Convert PNG images to JPG in Java

In various scenarios, you may need to reduce the size of the PNG images. In such cases, PNG to JPG conversion is commonly practiced. To automate this conversion from within the Java applications, this article shows how to convert a PNG image to JPG in Java.

Convert PNG to JPG in Java - API Installation

To convert PNG images to JPEG format, we will use Aspose.Imaging for Java. It is a feature-rich image processing API for the manipulation of a wide range of image formats. The API also provides a powerful image converter to convert images from one format to another. You can either download the API’s JAR or install it using Maven.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-imaging-java</artifactId>
    <version>21.12</version>
    <classifier>jdk16</classifier>
</dependency>

How to Convert PNG to JPG in Java

The following are the steps to convert a PNG image to JPG format.

  • Load the PNG image from file.
  • Save PNG as JPG image to the desired location.

That’s it.

Let’s now have a look at how to convert a PNG image to JPG format in Java.

Save a PNG Image as JPG in Java

Aspose.Imaging for Java involves only a couple of steps to perform PNG to JPG conversion. Just load the PNG image and save it in JPG format. Let’s see how to convert a PNG image to JPG in Java.

The following code sample shows how to save a PNG image as JPG in Java.

Java PNG to JPG Converter - Get a Free License

You can get a free temporary license to convert PNG images to JPG format without evaluation limitations.

Conclusion

In this article, you have learned how to convert PNG images to JPG in Java. You can simply install the API and integrate provided code sample to automate PNG to JPG conversion from within your Java applications. In addition, you can explore more about the Java image processing API using documentation. Also, you can post your queries on our forum.

See Also