# Fast blur in JAVA2D

**URL:** https://discourse.processing.org/t/fast-blur-in-java2d/690
**Category:** Coding Questions
**Created:** [June 3, 2018, 9:00pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690 "2018-06-03T21:00:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![lqdev](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lqdev/32/29_2.png) [@lqdev](https://discourse.processing.org/u/lqdev)
#### Post date: [June 3, 2018, 9:00pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/1 "2018-06-03T21:00:06Z")

</div>

Hello,

I need some fast blur for a sketch I am making. So far I have only tried `filter()`, but

1. it is slow
2. I need to blur only an area, not the entire image

The blur needs to run smoothly at 60 fps. Is this possible with JAVA2D?

---

<div class="post-metadata">

### Author: ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)
#### Post date: [June 3, 2018, 11:09pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/2 "2018-06-03T23:09:16Z")

</div>

Hi @lqdev I assume you already tried the Pimage filter in processing And the `frameRate()` function?  
[https://processing.org/reference/PImage\_filter\_.html](https://processing.org/reference/PImage_filter_.html)  
Can you explain your project in more detail please? 🙂

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [June 3, 2018, 11:30pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/3 "2018-06-03T23:30:19Z")

</div>

Hi,

Have you tried the blur pass from the [PostFx library](https://github.com/cansik/processing-postfx) ? It’s pretty fast.

---

<div class="post-metadata">

### Author: ![lqdev](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lqdev/32/29_2.png) [@lqdev](https://discourse.processing.org/u/lqdev)
#### Post date: [June 4, 2018, 5:47am UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/4 "2018-06-04T05:47:07Z")

</div>

The problem is, that I need the JAVA2D renderer, because it’s the only one that supports `clip()` properly.

---

<div class="post-metadata">

### Author: ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)
#### Post date: [June 25, 2018, 12:15pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/5 "2018-06-25T12:15:30Z")

</div>

Well instead of writing an efficient bur implementation in JAVA2D (which is not really possible), I would recommend you to write a shader which clips the output of your sketch 🙂

But first, tell us a bit more about the clipping problem you experience in P2D?

---

<div class="post-metadata">

### Author: ![lqdev](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lqdev/32/29_2.png) [@lqdev](https://discourse.processing.org/u/lqdev)
#### Post date: [June 25, 2018, 8:28pm UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/6 "2018-06-25T20:28:20Z")

</div>

I have already switched to FX2D, which solves my blur problems (and I used a `clip()`/`noClip()` support workaround), and improves overall performance **a lot**.

Anyways, the problem with `clip()` in P2D and P3D is that transformations don’t apply to the clip. An issue has already been reported on this problem.

---

<div class="post-metadata">

### Author: ![lqdev](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lqdev/32/29_2.png) [@lqdev](https://discourse.processing.org/u/lqdev)
#### Post date: [July 25, 2018, 10:30am UTC](https://discourse.processing.org/t/fast-blur-in-java2d/690/7 "2018-07-25T10:30:22Z")

</div>

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:

```auto
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.
