java 如何模糊图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1589760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:11:29  来源:igfitidea点击:

How do I blur an image?

javaimageruntimeeffect

提问by zero juan

I'm trying to implement a blurring mechanic on a java game. How do I create a blur effect on runtime?

我正在尝试在 Java 游戏中实现模糊机制。如何在运行时创建模糊效果?

回答by Dean J

Google "Gaussian Blur", try this: http://www.jhlabs.com/ip/blurring.html

谷歌“高斯模糊”,试试这个: http://www.jhlabs.com/ip/blurring.html

回答by JonoW

Read about/Google "Convolution Filters", it's a method of changing a pixels value based on the values of pixels around it. So apart from blurring, you can also do image sharpening and line-finding.

阅读/谷歌“卷积过滤器”,这是一种根据周围像素值更改像素值的方法。因此,除了模糊之外,您还可以进行图像锐化和寻线。

回答by Paul

If you are doing java game development, I'm willing to bet you are using java2d.

如果您从事 Java 游戏开发,我敢打赌您使用的是 java2d。

You want to create a convolution filter like so:

你想像这样创建一个卷积过滤器:

 // Create the kernel.
 kernel = new KernelJAI
 float[] = {  0.0F, -1.0F,  0.0F,
             -1.0F,  5.0F, -1.0F,
              0.0F, -1.0F,  0.0F };

 // Create the convolve operation.
 blurredImage = JAI.create("convolve", originalImage, kernel);

You can find more information at: http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-enhance.doc.html#51172(which is where the code is from too)

您可以在以下位置找到更多信息:http: //java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-enhance.doc.html#51172(这也是代码的来源)