import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* 作成日期: 2009-11-13 上午10:35:12<br/>
* 功能描述: 通过imageIo更改图片的类型<br/>
*/
public class ImageTypeConverter {
public static void main(String args[])throws Exception{
String scrUrl = "D:/My Documents/temp/p1.jpg";
String tarUrl = "D:/My Documents/temp/p1.png";
String type = "png";
changeImageType(scrUrl,type,tarUrl);
}
/**
* @fuction 以某种类型转存图片
* @param srcUrl 源图片路径
* @param type 目标图片类型
* @param tarUrl 目标图片路径
*/
public static void changeImageType(String srcUrl,String type,String tarUrl){
try {
File inputFile = new File(srcUrl);
BufferedImage bufImage = ImageIO.read(inputFile);
//转换为png格式
File outputFile = new File(tarUrl);
ImageIO.write(bufImage, type, outputFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}