The image is clipped after convolve

Here is my code snippet:

class cursorextends JComponent{

GeneralPath cursor =new GeneralPath();

int width;

int height;

int gkRadius = 5;

public cursor(){

setBackground(Color.black);

cursor.moveTo(0.0f, 0.0f);

cursor.lineTo(0.0f, 20.0f);

cursor.lineTo(4.0f, 16.0f);

cursor.lineTo(5.0f, 17.0f);

cursor.lineTo(10.0f, 26.0f);

cursor.lineTo(12.0f, 26.0f);

cursor.lineTo(13.0f, 25.0f);

cursor.lineTo(8.0f, 14.0f);

cursor.lineTo(14.0f, 14.0f);

cursor.closePath();

width = cursor.getBounds().width;

height= cursor.getBounds().height;

}

publicvoid paint(Graphics _g){

super.paint(_g);

BufferedImage im2;

Graphics2D g2d;

im2 =new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);

g2d = im2.createGraphics();

//Set the background to black

g2d.setBackground(getBackground());

g2d.clearRect(0,0,width,height);

g2d.setPaint(Color.gray);

g2d.fill(cursor);

// Blur the image

ConvolveOp blur =new ConvolveOp(new GaussianKernel(gkRadius));

BufferedImage im = blur.filter(im2,null);

Graphics2D g = (Graphics2D)_g;

g.drawImage(im, null,null);

}

}

Before i add the convolve operation, the generated image im

looks fine. However after i blur it, the generated image im2

is clipped. The width and height is different before the blurred operatoin.

Does anyone tell me why and what's the modification?

[2272 byte] By [yoursguideline] at [2007-9-26 4:41:58]
# 1

Use the constructor ConvolveOp(Kernel kernel, int edgeCondition, RenderingHints hints) so that you can specify how the edges are handled. By default, EDGE_ZERO_FILL is used, which results in zeros being copied at the edges, vs. EDGE_NO_OP, which copies the original edge pixels. The convolution implementation results in a dead band around the image that isn't filtered since it doesn't make any assumptions about what exists beyond the image. It could assume that the edge pixels extend indefinitely, or that the image wraps on itself, but the J2D implementation doesn't. It just starts the convolution inset by half the kernel size and fills the edges according to the edgeCondition argument. To filter at the edges, you would have to start with a larger initial image to give it something more to work with.

-- Kevin

kweiner at 2007-6-29 18:04:43 > top of Java-index,Security,Cryptography...