class="java" name="code"> import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class T { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { File srcfile = new File("d:\\Desert.jpg"); //载入图片文件 Image src = javax.imageio.ImageIO.read(srcfile); int width = src.getWidth(null); //得到源图宽 int h0 = src.getHeight(null); //得到源图长 if(width > 720) { BufferedImage tag= new BufferedImage(720, 720*h0/width, BufferedImage.TYPE_INT_RGB); //保存文件 //绘制缩小后的图 tag.getGraphics().drawImage(src.getScaledInstance(720, 720*h0/width, Image.SCALE_SMOOTH), 0, 0, null); ImageIO.write(tag, "JPEG", new FileOutputStream(srcfile)); } } }