Fast blur in JAVA2D

The solution for FX2D is very simple! However, it works different than filter(), but for my case it is perfect. Unfortunately this won’t work on other renderers, here’s the code:

void draw() {
  GraphicsContext ctx = ((Canvas) surface.getNative()).getGraphicsContext2D();
  GaussianBlur blur = new GaussianBlur();
  blur.setRadius(10);
  ctx.setEffect(blur);
  // do some drawing, anything drawn from here on will be blured
  // to disable the effect, do:
  ctx.setEffect(null);
}

JavaFX includes multiple more effects, like Glow and DropShadow, be sure to check them out if you want lag-free effects.
Don’t remember which package they’re from, you’ll have to search yourself.

2 Likes