drawing a single point

  • Thread starter Thread starter Steve DuMosch [MSFT]
  • Start date Start date
Ok, dumb question, but how do you draw a single point in gdi? I thought you
could use the .DrawLine method and just specify the same start and end
point, but that does nothing. In otherwords, if I have:

g.DrawLine(myPen,x,y,x,y)

nothing happens. I can have:

g.DrawLine(myPen,x,y,x+1,y+1)

and I can see what I am wanting, but obviously it's kinda' wierd-ish. So
how do you draw an individual point? (DrawElipse has the same problem).

Thanks,

D


````````````````````````````````
 
Hi D, Hi,

As you've found, DrawLine (oPenSesame, X, Y, X, Y) gives you nothing.

This is by design - and I'd like to know by who, come on own up!! I first
came across it in VB3 when doing owner-drawn controls and it makes a right
mess of the code when you want to be pixel-perfect. A line is always drawn
just short of the specified endpoint so, to get your line, you have to extend
the co-ordinates. Bad news when doing diagonals! I think I read somewhere once
that it's something to do with making it easy to draw sequences of lines? I
wish they'd left it 'harder' for us.

Regards,
Fergus
 
MC D said:
Ok, dumb question, but how do you draw a single point in gdi? I thought you
could use the .DrawLine method and just specify the same start and end
point, but that does nothing. In otherwords, if I have:

g.DrawLine(myPen,x,y,x,y)

nothing happens. I can have:

g.DrawLine(myPen,x,y,x+1,y+1)

and I can see what I am wanting, but obviously it's kinda' wierd-ish. So
how do you draw an individual point? (DrawElipse has the same problem).

\\\
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.FillRectangle( _
Brushes.Red, _
New Rectangle(100, 100, 1, 1) _
)
End Sub
///
 
Hello, Fergus:

You have information about how lines and polygons are drawn in the DirectX documentation: http://msdn.microsoft.com/library/d...natesystems/rasterizationrules.asp?frame=true

I hope its instructive.

Regards.


"Fergus Cooney" <[email protected]> escribió en el mensaje | Hi D, Hi,
|
| As you've found, DrawLine (oPenSesame, X, Y, X, Y) gives you nothing.
|
| This is by design - and I'd like to know by who, come on own up!! I first
| came across it in VB3 when doing owner-drawn controls and it makes a right
| mess of the code when you want to be pixel-perfect. A line is always drawn
| just short of the specified endpoint so, to get your line, you have to extend
| the co-ordinates. Bad news when doing diagonals! I think I read somewhere once
| that it's something to do with making it easy to draw sequences of lines? I
| wish they'd left it 'harder' for us.
|
| Regards,
| Fergus
|
|
 
Hello, Herfried:

I don't know how GDI+ is internally optimized but, don't you think DrawLine consumes less process time than FillRectangle for the same purpose? Ok, I know that for a single dot it's not important, but it could be for a large number of dots.

Does anybody know why doesn't exist a DrawPoint function? Or a DrawMarker?

Regards.


"Herfried K. Wagner [MVP]" <[email protected]> escribió en el mensaje | "MC D" <[email protected]> scripsit:
| > Ok, dumb question, but how do you draw a single point in gdi? I thought you
| > could use the .DrawLine method and just specify the same start and end
| > point, but that does nothing. In otherwords, if I have:
| >
| > g.DrawLine(myPen,x,y,x,y)
| >
| > nothing happens. I can have:
| >
| > g.DrawLine(myPen,x,y,x+1,y+1)
| >
| > and I can see what I am wanting, but obviously it's kinda' wierd-ish. So
| > how do you draw an individual point? (DrawElipse has the same problem).
|
| \\\
| Private Sub Form1_Paint( _
| ByVal sender As Object, _
| ByVal e As System.Windows.Forms.PaintEventArgs _
| ) Handles MyBase.Paint
| e.Graphics.FillRectangle( _
| Brushes.Red, _
| New Rectangle(100, 100, 1, 1) _
| )
| End Sub
| ///
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| <http://www.mvps.org/dotnet>
 
José Manuel Agüero said:
I don't know how GDI+ is internally optimized but, don't you think DrawLine consumes less process time than FillRectangle for the same purpose? Ok, I know that for a single dot it's not important, but it could be for a large number of dots.

I remember DrawLine placed the point on the wrong position or it didn't
draw it at all...
 
Hello, Herfried:

You are right... partially. In fact the last point of a line is never displayed. I haven't been able to find complete information, only a sample graphic in http://msdn.microsoft.com/library/d...hapes/overviewofvectorgraphics.asp?frame=true that doesn't contain an explanation. You can see in the line sample that the last pixel is not displayed.
So, to draw a pixel at (10, 20) you should use, for example, drawline(pen,10,20,11,20). That is, ending one pixel to the right (or up or left or down, it's the same)

Regards.


"Herfried K. Wagner [MVP]" <[email protected]> escribió en el mensaje | José Manuel Agüero <jmaguero, cliente de vodafone (es)> scripsit:
| > I don't know how GDI+ is internally optimized but, don't you think DrawLine consumes less process time than FillRectangle for the same purpose? Ok, I know that for a single dot it's not important, but it could be for a large number of dots.
|
| I remember DrawLine placed the point on the wrong position or it didn't
| draw it at all...
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| <http://www.mvps.org/dotnet>
 
Hi Jose,

Thanks for the link 0 it was interesting. Makes you wonder when even such
small things as a two pixel lines is considered as a triangle!!

Regards,
Fergus
 
Back
Top