Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 15, 2021 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/39cf2f9708713e487dfa66021b888285 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/39cf2f9708713e487dfa66021b888285 to your computer and use it in GitHub Desktop.
Convert PNG to JPG or JPG to PNG in Java
// Load JPG image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.jpg");
// Create and set PNG options
com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions();
options.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
// Save image as PNG
image.save("jpg-to-png.png", options);
// Load PNG image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.png");
// Save image as JPG
image.save("png-to-jpg.jpg", new com.aspose.imaging.imageoptions.JpegOptions());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment