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. Visual Basic
  4. Drawing one pixel, for a graph based program

Drawing one pixel, for a graph based program

Scheduled Pinned Locked Moved Visual Basic
graphicshelpdata-structurestutorialquestion
3 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.
  • F Offline
    F Offline
    Fu Manchu
    wrote on last edited by
    #1

    hi all, i am working on my final project for uni, PC based scope, just thinking about how windows plots and draws the the screen is very different to ya basic graph, for example 0,0 is in the top left-hand corner of the screen. That's not a problem, you just subtract the height from the plotted data. The biggest problems will come from the integer based xy coordinates, for example plotting sin(2*pi*f*t) will need to be scaled and rounded, resulting in trucation error. For now i need a way of plotting one pixel,when you use drawlines there is acually two which does not look pretty when plotting graphs, its look jaggered. for example using this code... myGraphics.DrawLine(myPen, 100, 100, 101, 100) when this is drawn the line looks like its made of two pixels. one way round this is this code... Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles MyBase.Paint Me.PlotFunction(100, 100, Color.Red, Me) End Sub Private Function PlotFunction(ByVal x As Integer, ByVal y As Integer, ByVal colour As Color, ByVal hnd As Object) 'return the current form as a drawing surface Dim myGraphics = Graphics.FromHwnd(hnd.Handle) 'instantiate a new pen object using the color structure Dim myPen = New Pen(Color:=colour, Width:=1) Dim maskpen = New Pen(Color:=hnd.BackColor, Width:=1) 'draw the line on the form using the pen object myGraphics.DrawLine(myPen, x, y, x + 1, y) 'draw the mask the blank out second pixel myGraphics.DrawLine(maskpen, x + 1, y, x + 2, y) End Function this works by blanking out the second pixel with the base colour of the form. any ideas or easier way of doing this? thanks Andy

    D J 2 Replies Last reply
    0
    • F Fu Manchu

      hi all, i am working on my final project for uni, PC based scope, just thinking about how windows plots and draws the the screen is very different to ya basic graph, for example 0,0 is in the top left-hand corner of the screen. That's not a problem, you just subtract the height from the plotted data. The biggest problems will come from the integer based xy coordinates, for example plotting sin(2*pi*f*t) will need to be scaled and rounded, resulting in trucation error. For now i need a way of plotting one pixel,when you use drawlines there is acually two which does not look pretty when plotting graphs, its look jaggered. for example using this code... myGraphics.DrawLine(myPen, 100, 100, 101, 100) when this is drawn the line looks like its made of two pixels. one way round this is this code... Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles MyBase.Paint Me.PlotFunction(100, 100, Color.Red, Me) End Sub Private Function PlotFunction(ByVal x As Integer, ByVal y As Integer, ByVal colour As Color, ByVal hnd As Object) 'return the current form as a drawing surface Dim myGraphics = Graphics.FromHwnd(hnd.Handle) 'instantiate a new pen object using the color structure Dim myPen = New Pen(Color:=colour, Width:=1) Dim maskpen = New Pen(Color:=hnd.BackColor, Width:=1) 'draw the line on the form using the pen object myGraphics.DrawLine(myPen, x, y, x + 1, y) 'draw the mask the blank out second pixel myGraphics.DrawLine(maskpen, x + 1, y, x + 2, y) End Function this works by blanking out the second pixel with the base colour of the form. any ideas or easier way of doing this? thanks Andy

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Create a single pixel bitmap in the color you need, then use Graphics.DrawImageUnscaled to draw that image at the coordinates you need. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • F Fu Manchu

        hi all, i am working on my final project for uni, PC based scope, just thinking about how windows plots and draws the the screen is very different to ya basic graph, for example 0,0 is in the top left-hand corner of the screen. That's not a problem, you just subtract the height from the plotted data. The biggest problems will come from the integer based xy coordinates, for example plotting sin(2*pi*f*t) will need to be scaled and rounded, resulting in trucation error. For now i need a way of plotting one pixel,when you use drawlines there is acually two which does not look pretty when plotting graphs, its look jaggered. for example using this code... myGraphics.DrawLine(myPen, 100, 100, 101, 100) when this is drawn the line looks like its made of two pixels. one way round this is this code... Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles MyBase.Paint Me.PlotFunction(100, 100, Color.Red, Me) End Sub Private Function PlotFunction(ByVal x As Integer, ByVal y As Integer, ByVal colour As Color, ByVal hnd As Object) 'return the current form as a drawing surface Dim myGraphics = Graphics.FromHwnd(hnd.Handle) 'instantiate a new pen object using the color structure Dim myPen = New Pen(Color:=colour, Width:=1) Dim maskpen = New Pen(Color:=hnd.BackColor, Width:=1) 'draw the line on the form using the pen object myGraphics.DrawLine(myPen, x, y, x + 1, y) 'draw the mask the blank out second pixel myGraphics.DrawLine(maskpen, x + 1, y, x + 2, y) End Function this works by blanking out the second pixel with the base colour of the form. any ideas or easier way of doing this? thanks Andy

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Ive always just used DrawRectangle(x,y,1,1) Never had any specific problems with this.

        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