Does anyone know how to convert a Region to a GraphicsPath object?
--
Urmas Ala
ummi@soft
Spichernstr 4
24116 Kiel
Tel.: 0431/2474389
Also, check this previous thread on the same question:
http://www.dotnet247.com/247reference/msgs/7/38527.aspx
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
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...
--
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...
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.
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...
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 ;)
--
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...