Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Region To GraphicsPath

682 views
Skip to first unread message

Urmas Ala

unread,
Nov 25, 2005, 7:27:01 AM11/25/05
to
hi,

Does anyone know how to convert a Region to a GraphicsPath object?

--
Urmas Ala
ummi@soft
Spichernstr 4
24116 Kiel
Tel.: 0431/2474389


Jelle van der Beek

unread,
Nov 25, 2005, 9:39:10 AM11/25/05
to
AFAIK there is no way to convert back to a GraphicsPath. Can you explain what
you are trying to accomplish?


Also, check this previous thread on the same question:

http://www.dotnet247.com/247reference/msgs/7/38527.aspx

Jelle van der Beek

unread,
Nov 25, 2005, 9:56:05 AM11/25/05
to
Ignore my last email...

You can try to use Region.GetRegionScans, which will return an approximation
of the region by returning a list of rectangles. From the rectangles you can
create a GraphicsPath.

Bob Powell has an article on this method which describes a bug in the .NET
1.1 version, which is fixed in 2.0.

http://www.bobpowell.net/getregionscansbug.htm

Hope this helps,
Jelle

Urmas Ala

unread,
Nov 25, 2005, 11:37:40 AM11/25/05
to
very simple:
Graphics.DrawPath((Pen),(RegionToPath?)(Form).Region);


--
Urmas Ala
ummi@soft
Spichernstr 4
24116 Kiel
Tel.: 0431/2474389

"Jelle van der Beek" <Jelleva...@discussions.microsoft.com> schrieb im
Newsbeitrag news:BF46E492-DC42-4438...@microsoft.com...

Jelle van der Beek

unread,
Nov 25, 2005, 12:00:02 PM11/25/05
to
In that case... how about Graphics.FillRegion ?

Urmas Ala

unread,
Nov 25, 2005, 5:30:33 PM11/25/05
to
thanks.
but Draw is not Fill?
I will Draw Region outline.

--
Urmas Ala
ummi@soft
Spichernstr 4
24116 Kiel
Tel.: 0431/2474389
"Jelle van der Beek" <Jelleva...@discussions.microsoft.com> schrieb im

Newsbeitrag news:00D86486-43B3-434F...@microsoft.com...

Jelle van der Beek

unread,
Nov 26, 2005, 3:50:03 AM11/26/05
to
Ok, there is a lot to tell about what you are trying to accomplish:

1. You seem to think that if you'd convert a Region to a GraphicsPath, that
you would be able to draw its outline. Well, that is true, but probably not
in a way that you would expect. Graphics.DrawPath will draw the outlines of
all the figures in its path. So if you have several primitives or closed
figures in the path, it will draw all the outlines of these figures. That's
not what you want.
In one of my previous posts I suggested to use Region.GetRegionScans to
obtain a list of rectangles from the region. From here on you could construct
a graphics path, but drawing it will most probably result in outlining
multiple figures.

But there is hope! GDI+ actually supports creating an outline, but it is not
exposed, and it seems that .NET 2.0 still doesn't expose it. But using
interop you can use it, and how it's done is described here:

http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/askgui11192002.asp

2. But... I wonder if you understand the purposes of Region and
GraphicsPath. Region is used for hit-testing and clipping, GraphicsPath for
painting. Creating a Region can only be done through rectangles and
GraphicsPath. In your case it would probably be a better idea to first create
a GraphicsPath and hold on to it. From the GraphicsPath, create a Region. If
you want to draw the outline, use the GraphicsPath. If you're lucky, you will
have only one figure in your GraphicsPath, so you can actually use
Graphics.DrawPath to draw the outline. If you have multiple figures, use the
method as described in the link.

Hope this solves your problem. If I can find the time, I will try to make a
sample that demonstrates how it works.

Bob Powell [MVP]

unread,
Nov 30, 2005, 5:14:27 PM11/30/05
to
I did answer this before but for some reason many of my recent posts are not
showing up...

There is no exposed way to do this. Internally the data for a region is
similar to that of a GRaphicsPath but none of this is documented or exposed.
When you examine a region it's after conversion to a classic Win32 format
that defines a region as a list of rectangles.

Technically you could take the rectangles, sort all the edges and come up
with something that approximated the region but it's not an easy or indeed
reliable task.

It's far better if possible to maintain the points or the GraphicsPath from
which the region derives. If you don't have that then it's likely that
you're just dealing with the list of dirty rectangles from a clip rectangle.
Is this correct??


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Urmas Ala" <a...@parge.de> wrote in message
news:uHCkKub...@TK2MSFTNGP12.phx.gbl...

Jelle van der Beek

unread,
Dec 1, 2005, 2:28:07 PM12/1/05
to
Bob, do you by any chance know if using a Region that consists out of many
rectangles is more expensive then using a Region with very little rectangles?

The regions in my control library take up a lot of CPU time. I am using
non-rectangular controls and purely the assignment of the region to the
control takes up 20 percent of CPU time on a 3Ghz machine (when resizing the
form, the region is recalculated and reassigned). The Region.Clone method is
also very CPU-intensive.

Could it be due to resource clean-up? Or perhaps due to the complexity of
the region?

I've already posted this in several newsgroups, so you're my only hope ;)

Frank Hileman

unread,
Dec 1, 2005, 5:31:52 PM12/1/05
to
From my own experience, it is definitely more expensive, the more rectangles
you have. This is why we avoid controls as much as possible.

--
Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Jelle van der Beek" <Jelleva...@discussions.microsoft.com> wrote in
message news:1792B84C-0137-4AD3...@microsoft.com...

0 new messages