Discussion:
DrawLine Limitation?
(too old to reply)
Yos Nugroho via .NET 247
2005-03-15 06:27:07 UTC
Permalink
Hi,

Recently I stummbled on an unexpected, weird behavior of Graphics.DrawLine method.
This is an example code :

Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Point p1 = new Point(int.MaxValue, 0);
Point p2 = new Point(0, 0);
g.DrawLine(Pens.Black, p1, p2);
g.Dispose();
bmp.Dispose();

If I run the code, it will throw a System.OverflowException.
It seems that if the line is too long, the exception occurs.

I look into MSDN docs and found nothing about this.
Anybody can help please?

Thanks.
--------------------------------
Yos Nugroho

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>SV4ll44HbUalRXgHP7/RHA==</Id>
Bob Powell [MVP]
2005-03-16 17:03:20 UTC
Permalink
I'm sure if you could create a bitmap or find a printer that was 353 miles
across it would work just fine...;-)

In fact the horizontal and vertical extent maximums are 1073741951 or
0x4000007F

I don't know why these figures are set because they don't seem sensible by
any decimal or binary system but that's the values.

This means that in reality you cannot draw on an image larger than 176 miles
on a side.
--
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.
Post by Yos Nugroho via .NET 247
Hi,
Recently I stummbled on an unexpected, weird behavior of Graphics.DrawLine method.
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Point p1 = new Point(int.MaxValue, 0);
Point p2 = new Point(0, 0);
g.DrawLine(Pens.Black, p1, p2);
g.Dispose();
bmp.Dispose();
If I run the code, it will throw a System.OverflowException.
It seems that if the line is too long, the exception occurs.
I look into MSDN docs and found nothing about this.
Anybody can help please?
Thanks.
--------------------------------
Yos Nugroho
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>SV4ll44HbUalRXgHP7/RHA==</Id>
Bob Powell [MVP]
2005-03-16 17:41:12 UTC
Permalink
For fun you may be interested in this...

http://www.bobpowell.net/extents.htm
--
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.
Post by Yos Nugroho via .NET 247
Hi,
Recently I stummbled on an unexpected, weird behavior of Graphics.DrawLine method.
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Point p1 = new Point(int.MaxValue, 0);
Point p2 = new Point(0, 0);
g.DrawLine(Pens.Black, p1, p2);
g.Dispose();
bmp.Dispose();
If I run the code, it will throw a System.OverflowException.
It seems that if the line is too long, the exception occurs.
I look into MSDN docs and found nothing about this.
Anybody can help please?
Thanks.
--------------------------------
Yos Nugroho
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>SV4ll44HbUalRXgHP7/RHA==</Id>
Loading...