Image with rounded corners


#1

Hi,
can anybody help me with graphics?

I have an image objects and I need to draw them on the form but with rounded corners.
I went through Graphics methods, however there are only simple figures and whole rectangular image drawing.
Is there any suitable and fast way to do so?


#2

You could set a clip region to a roundrect (make a Path, use addRoundedRectangle, then set it as the clip on the Graphics).

Or, you could create an Image with an alpha channel, draw a rounded rectangle into the alpha channel to give it shape and draw the image via the Graphics.


#3

Thanks for the ideas,
however first one woudn’t work for me because I have an older JUCE versions and there are only rectangular Graphics clip regions.

Concerning the second one, I’m not sure that I understand all of it but I’ll try step by step.


#4

the simplest is to use an Image brush then fill a rounded rectangle with this brush


#5

thanks for an advice - works perfectly!!


#6

[quote=“TheVinn”]You could set a clip region to a roundrect (make a Path, use addRoundedRectangle, then set it as the clip on the Graphics).

Or, you could create an Image with an alpha channel, draw a rounded rectangle into the alpha channel to give it shape and draw the image via the Graphics.[/quote]

I know this is old, but I can’t seem to find a way to clip by a rounded rectangle.
Graphics.excludeClipRegion only receives rectangles, not paths… Is that even possible?


#7

You can use Graphics::reduceClipRegion, which takes a path.


#8

Right, missed that overload :slight_smile:

Thanks…