Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

blurring an image

807603May 1 2005 — edited Feb 15 2008
Hi!
I've got a problem with using ConvolveOp.filter.
Here's the code:
    public void blur() 
    {
        if(imgSrc!=null)
        {
            imgDest = new BufferedImage(imgSrc.getWidth(), imgSrc.getHeight(), BufferedImage.TYPE_INT_RGB);
            float weight = 1.0f/9.0f;
            float[] elements = new float[9]; // create 2D array

            // fill the array with nine equal elements
            for (int i = 0; i < 9; i++) {
                elements[i] = weight;
            }
            // use the array of elements as argument to create a Kernel
            Kernel myKernel = new Kernel(3, 3, elements);
            ConvolveOp simpleBlur = new ConvolveOp(myKernel);

            // sourceImage and destImage are instances of BufferedImage
            simpleBlur.filter(imgSrc, imgDest); // blur the image
            imgSrc = imgDest;
            update(getGraphics());
        }
    }
I copied this code from some tutorial and just added update(getGraphics()) but it doesn't work. I always get
"Exception in thread "AWT-EventQueue-0" java.awt.image.ImagingOpException: Unable to convolve src image
at java.awt.image.ConvolveOp.filter(ConvolveOp.java:180)"

I tried using Netbeans' debugger to check if the image is properly loaded however i always get "No current context" (anyone knows why?) but i'm almost sure that it's properly loaded because it's painted on the screen :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2008
Added on May 1 2005
12 comments
785 views