Java代码实现图片高斯模糊

Maven 地址: http://mvnrepository.com/artifact/com.jhlabs/filters
<dependency>
<groupId>com.jhlabs</groupId>
<artifactId>filters</artifactId>
<version>2.0.235-1</version>
</dependency>
Java代码例子一:
public static byte[] blur(byte[] data) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
BufferedImage img = ImageIO.read(bais);
GaussianFilter gaussianFilter = new GaussianFilter();
gaussianFilter.filter(img, img);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
return baos.toByteArray();
}
Java代码例子二:
// blur a target picture and save to destination picture
public static void gaussianBlur(String targetPath, String destinationPath) throws IOException {
GaussianFilter gaussianFilter = new GaussianFilter();
BufferedImage fromImage = ImageIO.read(new File(targetPath));
BufferedImage toImage = new BufferedImage(fromImage.getWidth(), fromImage.getHeight(), BufferedImage.TYPE_INT_RGB);
gaussianFilter.setRadius(150);
gaussianFilter.filter(fromImage, toImage);
ImageIO.write(toImage, "webp", new File(destinationPath));
}
效果如下:
点击量: 0
免责声明:本文资源均为自媒体平台“芒果XO”用户上传并发布,本平台仅提供信息存储服务,仅作为学习交流,其版权归出版社或原作者所有,本网站不对所涉及的版权问题负责。(如本文资源侵犯了您的权益,请发送邮件到phoenix.lam@mangoxo.com,或按此进行投诉,我们会及时作出处理)如果你下载本网站资源,表示您同意只将此资源用于参考、学习使用而非任何其他用途。收取的费用为整理资源的费用,非资源本身费用,请悉知。
本文链接 https://www.mangoxo.com/blog/Lo7nbe5G 版权所有,转载请保留地址链接,感谢!

☺
加载评论中