These are still “expensive” (up to a few ms) for larger images on first render, but caching makes them trivial to re-render.
Just add a melatonin::CachedBlur
member to your component, specifying the radius:
melatonin::CachedBlur blur { 48 };
In your paint call, you can use blur.render(mySourceImage)
as a juce::Image, like so:
g.drawImageAt (blur.render (mySourceImage), 0, 0);
or something fancier like:
g.drawImageTransformed (blur.render (mySourceImage), backgroundTransform);
Alternatively, if you have specific times you are updating the blur (such as capturing a screenshot when someone clicks to open a modal window), you can call blur.update
with the new image:
void updateBackgroundBlur()
{
blur.update (getParentComponent()->createComponentSnapshot (getContentBoundsInParent()));
}
You can then call render()
without needing to pass an image argument:
g.drawImageAt (blur.render(), 0, 0);
Leave a Reply