How to apply a blur filter for my program? [message #325250] |
Wed, 13 February 2008 08:48  |
Eclipse User |
|
|
|
Originally posted by: agostinacchio.gmail.com
Hi All!
I loaded a jpg image on my JScrollPane. I used:
g_image = JAI.create("fileload", g_filename);
where g_image is a PlanarImage;
I created a class named ImageClass in which I declared: BufferedImage
image2;
Then when the image is loaded I wrote:
image.image2 = g_image.getAsBufferedImage();
jScrollPane1.setViewportView(image);
and the image is shown;
Now I want to apply a filter to my image;
I declared:
public final float[] BLUR3x3 = {
0.1f, 0.1f, 0.1f, // low-pass filter kernel
0.1f, 0.2f, 0.1f,
0.1f, 0.1f, 0.1f
};
at the beginning of the file class and the method:
void Blur_actionPerformed(ActionEvent e)
{
BufferedImage imgDest= null;
float[] data = BLUR3x3;
if (g_rast != null)
{
Graphics2D l_g2 = (Graphics2D) image.getGraphics();
//image.image2.getRGB(0, 0, image.getWidth(), image.getHeight(), l, 0,
1);
imgDest = new BufferedImage
(image.image2.getWidth(),image.image2.getHeight(),
BufferedImage.TYPE_INT_RGB);
ConvolveOp cop2 = new ConvolveOp(new Kernel(3, 3, data),
ConvolveOp.EDGE_NO_OP, null );
l_g2.drawImage(imgDest , cop2, 0, 0);
image.image2 = imgDest;
image.repaint();
}
when the Blur button is pressed it runs this code but it shows a black
image!!
I think the problem is the the fact that imgDest has the type TYPE_INT_RGB
and the mask uses float number.
Can anyone help me? It's an hard problem for me becouse i am almost a
beginner.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04849 seconds