-2

I am working in java, and have an image being generated. When the mouse passes over the generated image, I need the image to use a blur or pixelation filter.

What methods should I use to accomplish this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ppst99
  • 69
  • 1
  • 13
  • i have just blurred the whole image using java.awt.image.ConvolveOp. – ppst99 Jan 24 '13 at 17:00
  • 1
    "What have you tried?", in other words, **can you paste here the code you tried?** – BackSlash Jan 24 '13 at 17:32
  • 1
    1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) The solution is probably to draw the sharp image, then apply a clip to the area under the mouse & draw the image that is blurred. – Andrew Thompson Jan 24 '13 at 21:14

2 Answers2

0

Look in here: http://www.java2s.com/Code/Java/2D-Graphics-GUI/ImageEffectSharpenblur.htm

You need define a Kernel with an array of whatever values you want, instantiate the ConvolveOp with the Kernal as an argument, and then filter the desired image.

Jimmt
  • 852
  • 2
  • 11
  • 29
  • Thanks but This only blurs the whole image. – ppst99 Jan 24 '13 at 19:03
  • i haven't implemented this myself but if you can blur the whole image you should be able to blur part of the image. Programmers have to think, you know... – Jimmt Jan 25 '13 at 00:32
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();
}
ppst99
  • 69
  • 1
  • 13