public static void reduceImg(File srcfile, String imgdist, int widthdist,
int heightdist) {
try {
Image src = javax.imageio.ImageIO.read(srcfile);
BufferedImage tag= new BufferedImage((int) widthdist, (int) heightdist,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src.getScaledInstance(widthdist, heightdist, Image.SCALE_SMOOTH), 0, 0, null);
FileOutputStream out = new FileOutputStream(imgdist);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
处理图片大小
最新推荐文章于 2021-08-02 17:52:28 发布