public class tt {
public static void main(String[] args) throws IOException
{
try {
resizeImage("D:\\11.jpg","E:\\33.jpg",1808,737);
} catch (IOException e) {
System.out.println("图片转换出现异常!");
}
}
public static void resizeImage(String srcImgPath, String distImgPath,
int width, int height) throws IOException {
File srcFile = new File(srcImgPath);
Image srcImg = ImageIO.read(srcFile);
BufferedImage buffImg = null;
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
buffImg.getGraphics().drawImage(
srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
0, null);
ImageIO.write(buffImg, "JPEG", new File(distImgPath));
}
}
java定义图片大小 java如何设置图片大小
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java Swing 如何设置图片大小
如下两行代码搞定: Image image = new ImageIcon("Img/ackground.jpg").getImage();//
java swing JAVA GUI Jframe 背景图片