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 :)