How to create a clip region from a path that includes the 'outline'?

Posted by mackenir on Stack Overflow See other posts from Stack Overflow or by mackenir
Published on 2010-06-10T10:38:38Z Indexed on 2010/06/10 10:42 UTC
Read the original article Hit count: 260

I am creating a rounded rectangle GraphicsPath (see red outline image below), and then using this as a clip region both when drawing graphics, and as the Region of a Form.

Unfortunately, although the path looks good, it doesn't work well as a region (see solid black image below)

Is there a way that I can generate a clipping region from the path that includes all the 'outline' pixels of the path? Do I need to generate a bitmap and then process this to create a region?

The rounded rectangle path:

rounded rectangle

When used as a clip region:

clip region

The discrepancy (red pixels are in the path outline, but outside the region. blue pixels are in both):

overlap

© Stack Overflow or respective owner

Related posts about winforms

Related posts about system.drawing