Re: ImageIO/BufferedImage behaving inconsistently from one day to the next.
In article <jrrfma$kdq$1@dont-email.me>, markspace <-@.> wrote:
> 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:
> >
> [...]
> 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};
>
> 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;
> }
> }
I couldn't resist adding a GUI:
<https://sites.google.com/site/trashgod/convolution>
and taking a picture:
<https://sites.google.com/site/trashgod/_/rsrc/1340216139027/convolution/ConvlPng.png>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
|