Drawing a line to a bitmap
-
Hey, I am trying to draw a line on a bitmap. I have tried using System.Drawing.Graphics, however this apparently only works with forms. When I try the following code:
System.Drawing.Graphics.DrawLine(drawerpen, lastpoint, currentpoint);
I get an error saying that I must create an object instance to use this. However, System.Drawing.Graphics has no constructors, so I cannot create an instance such as:System.Drawing.Graphics lineDrawer = new System.Drawing.Graphics();
How can I draw lines on a bitmap? -
Hey, I am trying to draw a line on a bitmap. I have tried using System.Drawing.Graphics, however this apparently only works with forms. When I try the following code:
System.Drawing.Graphics.DrawLine(drawerpen, lastpoint, currentpoint);
I get an error saying that I must create an object instance to use this. However, System.Drawing.Graphics has no constructors, so I cannot create an instance such as:System.Drawing.Graphics lineDrawer = new System.Drawing.Graphics();
How can I draw lines on a bitmap?Klazen wrote:
however this apparently only works with forms.
What makes you say that ?
Klazen wrote:
I get an error saying that I must create an object instance to use this
Yes.
Klazen wrote:
How can I draw lines on a bitmap?
Graphics graphics = Graphics.FromBitmap(myBitmap);
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Klazen wrote:
however this apparently only works with forms.
What makes you say that ?
Klazen wrote:
I get an error saying that I must create an object instance to use this
Yes.
Klazen wrote:
How can I draw lines on a bitmap?
Graphics graphics = Graphics.FromBitmap(myBitmap);
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Thank you very much :) I say that because the only working instance of Graphics I found was through a form, such as using it to draw lines on a form.
Ah, sure, because in the paint event, it's been created for you. A lot of .NET classes use static factory methods instead of constructors, that's always something that's good to look for, in that scenario.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )