1

I need to get a Gdi+ Region from a GraphicPath without filling it, and I don't know how to do it.

A draw is better than words, so here is what I want to do :

What I want to do

  1. I have an ellipse, than I want to be displayed unfilled (whith a known line width)
  2. I have a full rectangle, and I want it to substracte itself from the ellipse.
  3. Then, I want to get the ellipse, unfilled, with a substracted part

So, here is my code :

// lGraphics and lBrush defined upper...

// Graphic paths
GraphicsPath lGraphicPathEllipse;
GraphicsPath lGraphicPathRectangle;

// Rectangles
Rect lRectEllipse(0, 0, 100, 100);
Rect lRectRectangle(10, -10, 100, 80);

// Add the shapes to the graphic pathes
lGraphicPathEllipse.AddEllipse(lRectEllipse);
lGraphicPathRectangle.AddRectangle(lRectRectangle);

// Create the regions
Region lRegionEllipse(&lGraphicPathEllipse);
Region lRegionRectangle(&lGraphicPathRectangle);

// Exclude the rectangle from the ellipse
lRegionEllipse.Exclude(&lRegionRectangle);

// Draw the ellipse region
lGraphics->FillRegion(&lBrush, &lRegionEllipse);

The problem is that what I get is actually this :

What I get

It seemes like creating a Region from a GraphicPath automatically fill the region. Is it possible to get a Region from a GraphicPath with only the outline? By giving a Pen or a line width for instance?

I've read thing about the GraphicPath Widen function, but it doesn't really do what I want.

It's strange to see that a simple thing like this can't be done.

Or maybe I have miss something!

Thanks for any help, and have a good day.

Alex.

Asesh
  • 3,186
  • 2
  • 21
  • 31
Alex
  • 11
  • 2
  • 2
    You should create a [clipping region](https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-use-clipping-with-a-region), then call `Graphics::DrawEllipse()` to draw the ellipse normally. – zett42 Dec 27 '17 at 17:27
  • It solves my problem for the case I exposed as example, but it doesn't solve the opposite case, which is a possible case in my appalication : - The Ellipse is filled - The Rectangle is Unfilled - Then, what I expect to get is a plain Ellipse but with a part of the rectangle outline missing. I can't use your method in this case, because the SetClips has to be done on a region which I would build from the ellipse (from a GraphicsPath). And so, I will point on the same initial problem, which is the fact that creating a Region from a GraphicPath automatically fill the region. – Alex Dec 28 '17 at 10:16

0 Answers0