How do I blur an image?

泪湿孤枕 提交于 2019-11-26 23:39:58

问题


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


回答1:


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.




回答2:


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




回答3:


If you are doing java game development, I'm willing to bet you are using 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)



来源:https://stackoverflow.com/questions/1589760/how-do-i-blur-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!