Blurring an Image

You can also use Graphicizer to blur an image by clicking the Blur button. You can see the results in Figure 3.7, where the image has an out-of-focus look.

Figure 3.7. Blurring an image.

To blur an image, the code will simply combine the pixels surrounding a particular pixel. Here's what this looks like using a Kernel object and a ConvolveOp object:

 if(event.getSource() == button4){     bufferedImageBackup = bufferedImage;     Kernel kernel = new Kernel(3, 3, new float[]         {.25f, 0,  .25f,          0,   0,  0,          .25f, 0,  .25f});     ConvolveOp convolveOp = new ConvolveOp(kernel);     BufferedImage temp = new BufferedImage(         bufferedImage.getWidth(), bufferedImage.getHeight(),         BufferedImage.TYPE_INT_ARGB);     convolveOp.filter(bufferedImage, temp);     bufferedImage = temp;     repaint(); } 

And that's all it takesnow you can blur images just by clicking the Blur button.

    Java After Hours(c) 10 Projects You'll Never Do at Work
    Java After Hours: 10 Projects Youll Never Do at Work
    ISBN: 0672327473
    EAN: 2147483647
    Year: 2006
    Pages: 128

    Similar book on Amazon © 2008-2017.
    If you may any questions please contact us: