Java 如何在鼠标下模糊图像

Java 如何在鼠标下模糊图像,java,image,awt,mouseevent,java-2d,Java,Image,Awt,Mouseevent,Java 2d,我在java中工作,正在生成一个图像。当鼠标经过生成的图像时,我需要图像使用模糊或像素化过滤器 我应该使用什么方法来完成此任务?请查看以下内容: 您需要使用任意值的数组定义一个内核,用内核作为参数实例化ConvolveOp,然后过滤所需的图像。我刚刚使用java.awt.image.ConvolveOp模糊了整个图像。“您尝试了什么?”,换句话说,您能在这里粘贴您尝试的代码吗?1)为了更快地获得更好的帮助,张贴一封电子邮件。2) 解决方案可能是绘制清晰的图像,然后在鼠标下的区域应用一个剪辑并绘

我在java中工作,正在生成一个图像。当鼠标经过生成的图像时,我需要图像使用模糊或像素化过滤器

我应该使用什么方法来完成此任务?

请查看以下内容:


您需要使用任意值的数组定义一个内核,用内核作为参数实例化ConvolveOp,然后过滤所需的图像。

我刚刚使用java.awt.image.ConvolveOp模糊了整个图像。“您尝试了什么?”,换句话说,您能在这里粘贴您尝试的代码吗?1)为了更快地获得更好的帮助,张贴一封电子邮件。2) 解决方案可能是绘制清晰的图像,然后在鼠标下的区域应用一个剪辑并绘制模糊的图像。谢谢,但这只会模糊整个图像。我自己还没有实现这一点,但如果你可以模糊整个图像,你应该能够模糊图像的一部分。程序员必须思考,你知道。。。
public void test(int x, int y){ // Here x and y are the parameter thrown by mouseDragged() function
blur1 = displayImage; // blur1 is Image variable

blur2 = new BufferedImage(blur1.getWidth(this), blur1 //blur2 is BufferedImage Variable
    .getHeight(this), BufferedImage.TYPE_INT_RGB);
tst = blur2.createGraphics(); // tst is Graphics2D variable
tst.drawImage(blur1, 0, 0, this);
blur3 = new BufferedImage(blur1.getWidth(this), blur1 //blur3 is BufferedImage Variable
    .getHeight(this), BufferedImage.TYPE_INT_RGB);
float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
    0.0625f, 0.125f, 0.0625f };
Kernel kernel = new Kernel(3, 3, data);
ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
    null);
blur2 = OSC.getSubimage(x, y, 20, 20); // 20 is the size in pixels where the effect is applied
blur3 = OSC.getSubimage(x, y, 20, 20);
convolve.filter(blur2, blur3);    
  Graphics osg = OSC.getGraphics();
  osg.setColor(fillColor);
  osg.drawImage(blur3,x,y,null);
  osg.dispose();
  repaint();
}