GraphicsPath.Widen Throwing OutOfMemoryException

G

Guest

I am working on a user control that supports zooming in and out. It appears
that when the user is zoomed out a lot that the GraphicsPath.Widen method is
throwing an OutOfMemoryException.

To simulate this you can run the following code:

PointF[] points = new PointF[] { new PointF(0.06403162f, 244.35968f),
new PointF(242.231628f, 244.402359f) };

using(System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath())
{
path.AddLine(points[0], points[1]);

using(System.Drawing.Pen pen =
new Pen(Color.Black, 0.00853754953f))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

float diameter = 6f * 0.00213438738f;
float radius = diameter/2;

foreach(PointF point in points)
{
using(Brush endPointBrush = new SolidBrush(pen.Color))
path.AddEllipse(point.X - radius, point.Y - radius,
diameter, diameter);
}

path.Widen(pen);
}
}

Basically I am trying to understand why the exception is being thrown.
Knowing that I would like to do something that will prevent the exception and
create a region that includes the area I am trying to describe (if its larger
that's ok).
 
B

Bob Powell [MVP]

The widen routines have bugs in. See the GDI+ FAQ for the spirograph bug.

I seem to remember GraphicsPath having a problem with floating point arrays
too.

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

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

Guest

Looks like it was the floating points (or at least rounding everything up to
whole integers avoids the problem).

Thanks!
Paul

Bob Powell said:
The widen routines have bugs in. See the GDI+ FAQ for the spirograph bug.

I seem to remember GraphicsPath having a problem with floating point arrays
too.

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

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.





PaulR said:
I am working on a user control that supports zooming in and out. It
appears
that when the user is zoomed out a lot that the GraphicsPath.Widen method
is
throwing an OutOfMemoryException.

To simulate this you can run the following code:

PointF[] points = new PointF[] { new PointF(0.06403162f, 244.35968f),
new PointF(242.231628f, 244.402359f) };

using(System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath())
{
path.AddLine(points[0], points[1]);

using(System.Drawing.Pen pen =
new Pen(Color.Black, 0.00853754953f))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

float diameter = 6f * 0.00213438738f;
float radius = diameter/2;

foreach(PointF point in points)
{
using(Brush endPointBrush = new SolidBrush(pen.Color))
path.AddEllipse(point.X - radius, point.Y - radius,
diameter, diameter);
}

path.Widen(pen);
}
}

Basically I am trying to understand why the exception is being thrown.
Knowing that I would like to do something that will prevent the exception
and
create a region that includes the area I am trying to describe (if its
larger
that's ok).
 
Top