HighTechTalks DotNet Forums  

Graphics.DrawLines

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Graphics.DrawLines in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
RedLars
 
Posts: n/a

Default Graphics.DrawLines - 11-22-2007 , 09:23 AM






Originally posted this question
http://forums.microsoft.com/MSDN/Sho...44877&SiteID=1 but
realized it was the wrong forum.

These two examples might be bugs, missing documentation or me being silly.

This code bit generates an OverflowException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)};
using (Pen pen = new Pen(Color.Black))
{
g.DrawLines(pen, points);
}

It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a
limitation that leads to the exception. Can someone please verify this?

Obviously this is huge number and not a big deal (for me anyway). But I
thought maybe the fact that the method can throw such an exception and maybe
the limit should be mentioned in the docs
(http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx)

This code bit generates an OutOfMemoryException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)};
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.DashOffset = 1;
g.DrawLines(pen, points);
}

Dont know the source of this problem. Same points as above apply.

Appreciate any help.

Reply With Quote
  #2  
Old   
Patrick van Dijk
 
Posts: n/a

Default Re: Graphics.DrawLines - 11-23-2007 , 02:23 AM






Hi,

Using GDI+ as you are in C# you really must make sure your geometry is
within the bounds of your window/graphics.
Rendering very large lines, polygons or even very small ones, e.g.
where essentially you render a line on a single pixel
can lead to this kind of errors. I always assumed GDI+ would perform
some sort of intelligent clipping, but it doesn't.
The underlying draw line routines just really seem t try to render a
line, hence it might take a long time.
So either wrap it into a try..catch or perform some clipping of your
own...or perhaps better move to WPF.

Cheers,

Patrick




On Nov 22, 4:23 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote:
Quote:
Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=1but
realized it was the wrong forum.

These two examples might be bugs, missing documentation or me being silly.

This code bit generates an OverflowException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)};
using (Pen pen = new Pen(Color.Black))
{
g.DrawLines(pen, points);

}

It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a
limitation that leads to the exception. Can someone please verify this?

Obviously this is huge number and not a big deal (for me anyway). But I
thought maybe the fact that the method can throw such an exception and maybe
the limit should be mentioned in the docs
(http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx)

This code bit generates an OutOfMemoryException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)};
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.DashOffset = 1;
g.DrawLines(pen, points);

}

Dont know the source of this problem. Same points as above apply.

Appreciate any help.


Reply With Quote
  #3  
Old   
RedLars
 
Posts: n/a

Default Re: Graphics.DrawLines - 11-23-2007 , 06:21 AM



Thanks for your prompt reply.

In my opinion the OverflowException and limit should be added as a comment
to the MSDN doc's for the relevant api.

Did some future research into the OutOfMemoryException. While using the
following code (see below) the points array can contain any value upto +_
1,073,000,000 which is fine.

Graphics g = this.CreateGraphics();
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
g.DrawLines(pen, points);
}

However, by using DashStyle.Dot it appear (on my computer) that values of
excess of 53 000 000 will cause an OutOfMemoryException. When using
DashStyle.Dash the limit seems to be around 89 000 000 and with
DashStyle.DashDot it is apporximately 66 000 000. Are these limits hardware
(amount of memory on computer) related or driver\software releated, or a
fixed limit set my microsoft for each style?

Obviously these kinds of values should not happen but under very rare
circumstances we have encountered this problem. What would be a safe value to
replace a value that in todays system lead to an exception? (There might be
one or two points in the array that are corrupt\extremly high, and the rest
are valid - hence we want to draw the line even with some fault data).

Regards,
RedLars

"Patrick van Dijk" wrote:

Quote:
Hi,

Using GDI+ as you are in C# you really must make sure your geometry is
within the bounds of your window/graphics.
Rendering very large lines, polygons or even very small ones, e.g.
where essentially you render a line on a single pixel
can lead to this kind of errors. I always assumed GDI+ would perform
some sort of intelligent clipping, but it doesn't.
The underlying draw line routines just really seem t try to render a
line, hence it might take a long time.
So either wrap it into a try..catch or perform some clipping of your
own...or perhaps better move to WPF.

Cheers,

Patrick




On Nov 22, 4:23 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote:
Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=1but
realized it was the wrong forum.

These two examples might be bugs, missing documentation or me being silly.

This code bit generates an OverflowException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)};
using (Pen pen = new Pen(Color.Black))
{
g.DrawLines(pen, points);

}

It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a
limitation that leads to the exception. Can someone please verify this?

Obviously this is huge number and not a big deal (for me anyway). But I
thought maybe the fact that the method can throw such an exception and maybe
the limit should be mentioned in the docs
(http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx)

This code bit generates an OutOfMemoryException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)};
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.DashOffset = 1;
g.DrawLines(pen, points);

}

Dont know the source of this problem. Same points as above apply.

Appreciate any help.



Reply With Quote
  #4  
Old   
Patrick van Dijk
 
Posts: n/a

Default Re: Graphics.DrawLines - 11-24-2007 , 08:01 AM



Hi,

GDI+ is all about software rendering, it's the CPU doing it all and
almost nothing is done by the hardware.
I've never come accross any hardware graphics card supporting GDI+.
Most of them do support GDI, but that is a much lower level API.

Cheers,

Patrick

On Nov 23, 1:21 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote:
Quote:
Thanks for your prompt reply.

In my opinion the OverflowException and limit should be added as a comment
to the MSDN doc's for the relevant api.

Did some future research into the OutOfMemoryException. While using the
following code (see below) the points array can contain any value upto +_
1,073,000,000 which is fine.

Graphics g = this.CreateGraphics();
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
g.DrawLines(pen, points);

}

However, by using DashStyle.Dot it appear (on my computer) that values of
excess of 53 000 000 will cause an OutOfMemoryException. When using
DashStyle.Dash the limit seems to be around 89 000 000 and with
DashStyle.DashDot it is apporximately 66 000 000. Are these limits hardware
(amount of memory on computer) related or driver\software releated, or a
fixed limit set my microsoft for each style?

Obviously these kinds of values should not happen but under very rare
circumstances we have encountered this problem. What would be a safe value to
replace a value that in todays system lead to an exception? (There might be
one or two points in the array that are corrupt\extremly high, and the rest
are valid - hence we want to draw the line even with some fault data).

Regards,
RedLars

"Patrick van Dijk" wrote:

Hi,

Using GDI+ as you are in C# you really must make sure your geometry is
within the bounds of your window/graphics.
Rendering very large lines, polygons or even very small ones, e.g.
where essentially you render a line on a single pixel
can lead to this kind of errors. I always assumed GDI+ would perform
some sort of intelligent clipping, but it doesn't.
The underlying draw line routines just really seem t try to render a
line, hence it might take a long time.
So either wrap it into a try..catch or perform some clipping of your
own...or perhaps better move to WPF.

Cheers,

Patrick

On Nov 22, 4:23 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote:
Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=...
realized it was the wrong forum.

These two examples might be bugs, missing documentation or me being silly.

This code bit generates an OverflowException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)};
using (Pen pen = new Pen(Color.Black))
{
g.DrawLines(pen, points);

}

It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a
limitation that leads to the exception. Can someone please verify this?

Obviously this is huge number and not a big deal (for me anyway). But I
thought maybe the fact that the method can throw such an exception and maybe
the limit should be mentioned in the docs
(http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx)

This code bit generates an OutOfMemoryException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)};
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.DashOffset = 1;
g.DrawLines(pen, points);

}

Dont know the source of this problem. Same points as above apply.

Appreciate any help.


Reply With Quote
  #5  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Graphics.DrawLines - 11-24-2007 , 05:01 PM



The GDI+ FAQ has the exact drawing limits defined for you.

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


"RedLars" <RedLars (AT) discussions (DOT) microsoft.com> wrote

Quote:
Originally posted this question
http://forums.microsoft.com/MSDN/Sho...44877&SiteID=1 but
realized it was the wrong forum.

These two examples might be bugs, missing documentation or me being silly.

This code bit generates an OverflowException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)};
using (Pen pen = new Pen(Color.Black))
{
g.DrawLines(pen, points);
}

It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is
a
limitation that leads to the exception. Can someone please verify this?

Obviously this is huge number and not a big deal (for me anyway). But I
thought maybe the fact that the method can throw such an exception and
maybe
the limit should be mentioned in the docs
(http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx)

This code bit generates an OutOfMemoryException.
Graphics g = this.CreateGraphics();
Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)};
using (Pen pen = new Pen(Color.Black))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.DashOffset = 1;
g.DrawLines(pen, points);
}

Dont know the source of this problem. Same points as above apply.

Appreciate any help.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.