1 import java.awt.image.BufferedImage;
2 import java.io.File;
3 import java.io.IOException;
4 import javax.imageio.ImageIO;
5
6 public class ImageIOTest {
7 public static void main(String args[]) throws IOException {
8 File inputFile = new File("c:\\test.bmp");
9 BufferedImage input = ImageIO.read(inputFile);
10
11
12 File outputFile = new File("c:\\test.gif");
13 ImageIO.write(input, "GIF", outputFile);
14
15 outputFile = new File("c:\\test.jpeg");
16 ImageIO.write(input, "JPEG", outputFile);
17
18 outputFile = new File("c:\\test.jpg");
19 ImageIO.write(input, "JPG", outputFile);
20
21 outputFile = new File("c:\\test.png");
22 ImageIO.write(input, "PNG", outputFile);
23 }
24 }
一个512*384 纯黑的BMP格式图片是576KB
转换以后:
gif格式为790字节
jpeg格式为3.61KB
jpg格式为3.61KB
png格式为652字节
目前支持一下格式:
BMP, JPG,PNG, JPEG, WBMP, GIF
posted on 2007-01-03 10:09
交口称赞 阅读(772)
评论(1) 编辑 收藏 所属分类:
Java6