本文实例讲述了Java实现将png格式图片转换成jpg格式图片的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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:创建一个RBG图像,24位深度,成功将32位图转化成24位 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(); } } } |
希望本文所述对大家java程序设计有所帮助。
原文链接:http://blog.csdn.net/y824448940/article/details/51262007