/** * 缩放新的图片 */ public static String scaleImg(String waterLogoPath, String waterLogoPathTmp, String suffix, ImgWH wh) { try { suffix = suffix.replace(".", ""); File srcfile = new File(waterLogoPath); Image src = ImageIO.read(srcfile); //创建画布 BufferedImage bufferedImage = new BufferedImage(wh.getWidth(), wh.getHeight(), BufferedImage.TYPE_INT_RGB); //设为透明底色 BufferedImageGraphicsConfig config = BufferedImageGraphicsConfig.getConfig(bufferedImage); bufferedImage = config.createCompatibleImage(wh.getWidth(), wh.getHeight(), Transparency.TRANSLUCENT); //绘制 bufferedImage.getGraphics().drawImage(src.getScaledInstance(wh.getWidth(), wh.getHeight(), Image.SCALE_SMOOTH), 0, 0, null); //存储图片 ImageIO.write(bufferedImage, suffix, new File(waterLogoPathTmp)); } catch (Exception e) { e.printStackTrace(); return ExceptionUtils.getErrorStackTrace(e); } return null; }
标签:java,suffix,缩放,getHeight,bufferedImage,wh,String,图片 From: https://www.cnblogs.com/c2g5201314/p/17336445.html