all groups > dotnet drawing api > february 2006 >
You're in the

dotnet drawing api

group:

Finding specific point in region - how to?


Finding specific point in region - how to? marcin.rzeznicki NO[at]SPAM gmail.com
2/25/2006 8:42:59 AM
dotnet drawing api:
Hello,
I am in need to find specific point in region. To be exact:
Suppose, we have region like the one below

__________
| _____|
| |
| |
_____* <- this is the point (*) I am looking for, if one thought of
region as a block of lines and attached to each line bounding rectangle
then the point would be at (rectangle.Right, Rectangle.Top)

Another example could be:

______________
| |
| |
_____________* <- (this is the point) This case could be analyzed in
the same way as the one above, yielding point marked with *

I tried to win the problem with using GetRegionScans and computing the
point by comapring by procedure like:

RectangleF bounds = region.GetBounds(graphics);

if (char.IsWhiteSpace(lastCharInRegion))
{
if (lastCharInRegion == '\n')
return new PointF(bounds.X, bounds.Bottom);
}

float highestX = float.MinValue;
float lowestY = float.MaxValue;
foreach(RectangleF rectangle in
region.GetRegionScans(transformation))
{
if (rectangle.Bottom == bounds.Bottom)
{
highestX = Math.Max(higestX, rectangle.Right);
lowestY = Math.Min(lowestY, rectangle.Top);
}
}
return new PointF(highestX, lowestY);

but hte procedure works only if hard assumptions are taken:
GetRegionScans returns rectangles horizontally ordered, and each
rectangle has height of imaginary line - which might not be the case as
documentation do not specify any ordering or properties of returned
rectangles. Also, I've heard of GetRegionScnas bug which distracted me
from using it.
Another approach I thought of would not use any region at all, except
ectangular ones (regions are returned from MeasureCharacterRegions
method, so it is easy to achieve), but I am quite sure it would have
made my procedure less effective.
What is the best solution to my problem, in your opinion?
Re: Finding specific point in region - how to? Bob Powell [MVP]
2/27/2006 12:00:00 AM
You're pretty much on the right track. 1.1 does have a bug in GetRegionScans
but this has been fixed in 2.0.

If you can use VS2005 then the technique will work just fine.

--
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.





[quoted text, click to view]

Re: Finding specific point in region - how to? marcin.rzeznicki NO[at]SPAM gmail.com
2/27/2006 3:08:16 AM

Bob Powell [MVP] napisal(a):
[quoted text, click to view]

Unfortunately, I cannot :-( Is memory leak in GetRegionScans very
serious?
I am trying to write something like text editor, region I described is
block of text with constant properties like font style etc, the point I
seek would mark beginning of next text block. Assuming memory leak is
very serious - would you recommend scanning text "line by line" which
would give me only rectangular regions (possible loss of efficiency)?
I've also read some discussions which recommend leaving GDI+ in favour
of GDI when it comes to text rendering, could that be right choice for
..NET application?
By the way, your GDI+ faq is awesome :-) Thank you for your answer.
Re: Finding specific point in region - how to? Bob Powell [MVP]
2/27/2006 5:19:23 PM
The GetRegionScans leak is serious enough IMO. The thing leaks an unmanaged
memory block the size of the region every time you use it. I used it to read
regions for use in a DirectX based screen-transition library and a 1 meg
machine ground to a halt in about 15 minutes. Unfortunately, because it's
unmanaged memory that leaks, it's not reclaimed when the application is
stopped and one has to reset the machine.

If you're writing an on-screen editor (which I've done for a couple of
clients) you have to rely on MeasureString or MeasureCharacterRanges.

--
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.



[quoted text, click to view]

AddThis Social Bookmark Button