java - 缩放新的图片
/** * 缩放新的图片 */ 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; }
本文来自博客园,作者:岑惜,转载请注明原文链接:https://www.cnblogs.com/c2g5201314/p/17336445.html
响应开源精神相互学习,内容良币驱除劣币

浙公网安备 33010602011771号