public class Picture {
// TODO Auto-generated constructor stub
public static void resizePNG(String fromFile, String toFile, int outputWidth, int outputHeight,boolean proportion) {
try {
File f2 = new File(fromFile);
BufferedImage bi2 = ImageIO.read(f2);
int newWidth;
int newHeight;
// 判断是否是等比缩放
if (proportion == true) {
// 为等比缩放计算输出的图片宽度及高度
double rate1 = ((double) bi2.getWidth(null)) / (double) outputWidth + 0.1;
double rate2 = ((double) bi2.getHeight(null)) / (double) outputHeight + 0.1;
// 根据缩放比率大的进行缩放控制
double rate = rate1 < rate2 ? rate1 : rate2;
newWidth = (int) (((double) bi2.getWidth(null)) / rate);
newHeight = (int) (((double) bi2.getHeight(null)) / rate);
} else {
newWidth = outputWidth; // 输出