Drawing one pixel, for a graph based program
-
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 -
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 AndyCreate 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
-
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