-2

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

我应该使用什么方法来实现这一点?

4

2 回答 2

0

看这里: http ://www.java2s.com/Code/Java/2D-Graphics-GUI/ImageEffectSharpenblur.htm

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

于 2013-01-24T17:39:37.830 回答
0
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();
}
于 2013-02-18T16:19:43.493 回答