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. draw a single point

draw a single point

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
11 Posts 3 Posters 0 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.
  • R Rupel

    hi, i've searched the graphics-class, but i didn't found how to draw a single point. when i use g.DrawLine(pen,x,y,x+1,y); i get the two pixels connected. when i use g.DrawLine(pen,x,y,x,y); i get nothing. :( any idea? :wq

    S Offline
    S Offline
    Stephane Rodriguez
    wrote on last edited by
    #2

    I would suggest to spit on screen so you would get points on screens :-D More seriously, there is no DrawPoint method available. MS recommends to use GDI (Marshalled) which is still available. Or, if performance is an issue, go unmanaged, lock a ptr on a surface and start playing with it. Now AFAIK, I would recommend a simple to use FillEllipse(x,y,1*nZoomFactor,1*nZoomFactor) where nZoomFactor=1.


    And I swallow a small raisin.

    R 3 Replies Last reply
    0
    • R Rupel

      hi, i've searched the graphics-class, but i didn't found how to draw a single point. when i use g.DrawLine(pen,x,y,x+1,y); i get the two pixels connected. when i use g.DrawLine(pen,x,y,x,y); i get nothing. :( any idea? :wq

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #3

      SetPixel


      "When the only tool you have is a hammer, a sore thumb you will have."

      R 1 Reply Last reply
      0
      • S Stephane Rodriguez

        I would suggest to spit on screen so you would get points on screens :-D More seriously, there is no DrawPoint method available. MS recommends to use GDI (Marshalled) which is still available. Or, if performance is an issue, go unmanaged, lock a ptr on a surface and start playing with it. Now AFAIK, I would recommend a simple to use FillEllipse(x,y,1*nZoomFactor,1*nZoomFactor) where nZoomFactor=1.


        And I swallow a small raisin.

        R Offline
        R Offline
        Rupel
        wrote on last edited by
        #4

        :wtf: marshalled? unmanaged? wtf?! i only want to set a single pixel!!! X| it seems, i will try the fillellipse-thing... :| but thx for the tip! :rose: :wq

        S 1 Reply Last reply
        0
        • P Philip Fitzsimons

          SetPixel


          "When the only tool you have is a hammer, a sore thumb you will have."

          R Offline
          R Offline
          Rupel
          wrote on last edited by
          #5

          i don't want to draw on a bitmap but rather on a graphics-object :wq

          1 Reply Last reply
          0
          • R Rupel

            :wtf: marshalled? unmanaged? wtf?! i only want to set a single pixel!!! X| it seems, i will try the fillellipse-thing... :| but thx for the tip! :rose: :wq

            S Offline
            S Offline
            Stephane Rodriguez
            wrote on last edited by
            #6

            Here is the code,

            // -->declaration
            [DllImport("gdi32.dll", CharSet=CharSet.Auto)]
            static public extern int SetPixel(IntPtr hdc, int x, int y, int rgb); //

            // -->usage
            // assumption : you have a HDC in hand
            // cast your HDC to (IntPtr)
            // cast your COLORREF to (int)
            SetPixel(dc,x,y,rgb);


            And I swallow a small raisin.

            R 1 Reply Last reply
            0
            • S Stephane Rodriguez

              I would suggest to spit on screen so you would get points on screens :-D More seriously, there is no DrawPoint method available. MS recommends to use GDI (Marshalled) which is still available. Or, if performance is an issue, go unmanaged, lock a ptr on a surface and start playing with it. Now AFAIK, I would recommend a simple to use FillEllipse(x,y,1*nZoomFactor,1*nZoomFactor) where nZoomFactor=1.


              And I swallow a small raisin.

              R Offline
              R Offline
              Rupel
              wrote on last edited by
              #7

              FillEllipse(,,,1,1) does not solve the problem :( going marshalled... :~ :wq

              1 Reply Last reply
              0
              • S Stephane Rodriguez

                I would suggest to spit on screen so you would get points on screens :-D More seriously, there is no DrawPoint method available. MS recommends to use GDI (Marshalled) which is still available. Or, if performance is an issue, go unmanaged, lock a ptr on a surface and start playing with it. Now AFAIK, I would recommend a simple to use FillEllipse(x,y,1*nZoomFactor,1*nZoomFactor) where nZoomFactor=1.


                And I swallow a small raisin.

                R Offline
                R Offline
                Rupel
                wrote on last edited by
                #8

                MS recommends to use GDI (Marshalled) where do you know that from? how does someone get to know what MS recommends...? :wq

                1 Reply Last reply
                0
                • S Stephane Rodriguez

                  Here is the code,

                  // -->declaration
                  [DllImport("gdi32.dll", CharSet=CharSet.Auto)]
                  static public extern int SetPixel(IntPtr hdc, int x, int y, int rgb); //

                  // -->usage
                  // assumption : you have a HDC in hand
                  // cast your HDC to (IntPtr)
                  // cast your COLORREF to (int)
                  SetPixel(dc,x,y,rgb);


                  And I swallow a small raisin.

                  R Offline
                  R Offline
                  Rupel
                  wrote on last edited by
                  #9

                  phew. that works. thx! :rose: anyways - i still don't understand why ms doesn't include a DrawPoint(Pen,int,int) or DrawPoint(Pen,pt) function into the graphics-class. :confused: :wq

                  S 1 Reply Last reply
                  0
                  • R Rupel

                    phew. that works. thx! :rose: anyways - i still don't understand why ms doesn't include a DrawPoint(Pen,int,int) or DrawPoint(Pen,pt) function into the graphics-class. :confused: :wq

                    S Offline
                    S Offline
                    Stephane Rodriguez
                    wrote on last edited by
                    #10

                    I guess for known performance reasons MS didn't think that was a good idea to allow DrawPoint. Well to be honest, the fact that DrawLine(x,y,x,y) does not work properly is a bug. DirectX+GDI advocates have been fighting for years to train developers to lock a ptr to an actual surface, and then poking inside, instead of doing silly SetPixel loops. For real world apps such like real-time imaging, locking surfaces is of course the recommended solution,


                    And I swallow a small raisin.

                    R 1 Reply Last reply
                    0
                    • S Stephane Rodriguez

                      I guess for known performance reasons MS didn't think that was a good idea to allow DrawPoint. Well to be honest, the fact that DrawLine(x,y,x,y) does not work properly is a bug. DirectX+GDI advocates have been fighting for years to train developers to lock a ptr to an actual surface, and then poking inside, instead of doing silly SetPixel loops. For real world apps such like real-time imaging, locking surfaces is of course the recommended solution,


                      And I swallow a small raisin.

                      R Offline
                      R Offline
                      Rupel
                      wrote on last edited by
                      #11

                      hmm. might be a reason. when i think it over, i could have created a bitmap before the operation, set the pixels within the bitmap and draw the bitmap at the proper location... i see there's a trade-off between 'amount of code' and 'drawing speed' - but in my simple case the setpixel-speed is abolutely ok. :) :wq

                      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