利用JDK原生支持对png jpg gif格式图片做相互转换,结合脚本就可以达到批量处理的能力,比PS来的快啊!而且是JAVA代码 在Windows和Linux上都可以用。
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
*
*/
/**
* Created on 2011-5-24 Discription:[convert GIF->JPG GIF->PNG PNG->GIF(X)
* PNG->JPG ]
*
* @param source
* @param formatName
* @param result
* @author:dx[hzdengxu@163.com]
*/
class ImgConverter {
private String[] args;
public static void convert(String source, String formatName, String result) {
try {
File f = new File(source);
f.canRead();
BufferedImage src = ImageIO.read(f);
ImageIO.write(src, formatName, new File(result));
} catch (Exception e) {
e.printStackTrace();
}
}
public ImgConverter(String[] args) {
// TODO Auto-generated constructor stub
this.args = args;
}
public void run() {
if (this.args.length > 2) {
convert(this.args[0], this.args[1], this.args[2]);
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new ImgConverter(args).run();
}
}