Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drawing a line to a bitmap

Drawing a line to a bitmap

Scheduled Pinned Locked Moved C#
graphicsquestionhelp
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Klazen
    wrote on last edited by
    #1

    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?

    C 1 Reply Last reply
    0
    • K Klazen

      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?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      K 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        K Offline
        K Offline
        Klazen
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • K Klazen

          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.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups