On 6/19/2012 7:31 PM, Fred Greer wrote:
> I have code that used to work perfectly, which processes images in
> certain ways, and today it suddenly was not working. I hadn't changed the
> code at all. I tracked the problem down to spurious
> IllegalArgumentExceptions being thrown by this code:
>
> public class ImageUtils {
>
> private static float[] BLUR = {0.1111111, 0.1111111, 0.1111111,
> 0.1111111, 0.1111111, 0.1111111,
> 0.1111111, 0.1111111, 0.1111111}
> ...
> public static BufferedImage blur (BufferedImage img) {
> Kernel k = new Kernel(3, 3, BLUR);
> ConvolveOp co = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, null);
> BufferedImage dest = new BufferedImage(img.getWidth(),
> img.getHeight(),img.getType());
> co.filter(img,dest);
> return dest;
> }
> ...
> }
So this is the code you say isn't working? It works for me:
package quicktest;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import javax.imageio.ImageIO;
/**
*
* @author Brenden
*/
public class ConvlPng {
public static void main(String[] args)
throws Exception
{
BufferedImage png = ImageIO.read(
ConvlPng.class.getResourceAsStream( "conv_test.png" ) );
BufferedImage conv = blur( png );
System.out.println( conv );
}
private static float[] BLUR = {0.1111111f, 0.1111111f, 0.1111111f,
0.1111111f, 0.1111111f, 0.1111111f,
0.1111111f, 0.1111111f, 0.1111111f};