java对PNG图片圆角处理 保持PNG透明背景
2018-07-20 来源:open-open
/* * 圆角处理 * @param BufferedImage * @param cornerRadius * */ public static String makeRoundedCorner(String srcImageFile, String result, String type, int cornerRadius) { try { BufferedImage image = ImageIO.read(new File(srcImageFile)); int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); output = g2.getDeviceConfiguration().createCompatibleImage(w, h, Transparency.TRANSLUCENT); g2.dispose(); g2 = output.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillRoundRect(0, 0,w, h, cornerRadius, cornerRadius); g2.setComposite(AlphaComposite.SrcIn); g2.drawImage(image, 0, 0, w, h, null); g2.dispose(); ImageIO.write(output, type, new File(result)); return result; } catch (IOException e) { e.printStackTrace(); } return null; }
标签: isp
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐