[Test availability], pngjpg
This example describes how to convert a png image to a jpg image in Java. We will share this with you for your reference. The details are as follows:
Import java. awt. color; import java. awt. image. bufferedImage; import java. io. file; import java. io. IOException; import javax. imageio. imageIO; public class ConvertImageFile {public static void main (String [] args) {BufferedImage bufferedImage; try {// read image file bufferedImage = ImageIO. read (new File ("c: \ java.png"); // create a blank, RGB, same width and height, and a white // background BufferedImage newBufferedImage = new BufferedImage (bufferedImage. getWidth (), bufferedImage. getHeight (), BufferedImage. TYPE_INT_RGB); // TYPE_INT_RGB: creates an RBG image with 24-bit depth. The 32-Bit Bitmap is successfully converted into a 24-bit newBufferedImage. createGraphics (). drawImage (bufferedImage, 0, 0, Color. WHITE, null); // write to jpeg file ImageIO. write (newBufferedImage, "jpg", new File ("c: \ java.jpg"); System. out. println ("Done");} catch (IOException e) {e. printStackTrace ();}}}
PS: here we recommend several online image processing tools for your reference:
Online image format conversion (jpg/bmp/gif/png) tool:
Http://tools.jb51.net/aideddesign/picext
Online image cropping/generation tools:
Http://tools.jb51.net/aideddesign/imgcut
ICO icon generation tool:
Http://tools.jb51.net/aideddesign/ico_img
Online low polygon graphics generation tool:
Http://tools.jb51.net/aideddesign/img_lowpoly
For more java-related content, refer to this topic: java image operation skills summary, java Date and Time Operation Skills summary, Java operation DOM node skills summary, Java file and directory operation skills summary, and Java data structure and algorithm tutorial.
I hope this article will help you with java programming.