How do I blur an image?

后端 未结 3 1613
野性不改
野性不改 2020-12-07 04:54

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

3条回答
  •  被撕碎了的回忆
    2020-12-07 05:40

    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)

提交回复
热议问题