PathGradientBrush throws out-of memory exception

B

bipingm

In the following snippet of code,

GraphicsPath path = new GraphicsPath()
path.AddEllipse(0,0,X,X);
using (PathGradientBrush pgb = new PathGradientBrush(path))
{
pgb.CenterColor=Color.Red;
pgb.SurroundColors=new Color[]{Color.White};
e.Graphics.FillEllipse(pgb,0,0,X,X);
}

If X=0 (parameter to the AddEllipse function) then the call
new PathGradientBrush(path) throws an Out-of-Memory exception.

Is it possible to perform a check on the path variable(to see if it is
a closed region/just a single point) before invoking the
PathGradientBrush constructor?
George.
 
G

Guest

You could use path.GetBounds.Height and path.GetBounds.Width to checj the
sizes of the path.
 
F

Frank Hileman

I believe you will get that exception with other uses of the GraphicsPath as
well, so it is best to avoid creating one like that -- move the error
checking to a higher level, and leave path == null. Then check against null.

Regards,
Frank Hileman

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top