469,352 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Drawing a single pixel

This seems like a really stupid question, but here it goes........

is there a command to draw a single pixel?

The closest I can get is to draw a line that is 2 pixels wide, or do create
another image that's 1x1 with the color of the pixel, then do a DrawImage to
insert that image into the 'master' image...which seems like a huge waste!

Thanks.
Nov 21 '05 #1
9 12564
"Rob T" <RT*********@DONTwalchemSPAM.com> schrieb:
[Drawing a single pixel]


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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
See the GDI+ FAQ.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
This seems like a really stupid question, but here it goes........

is there a command to draw a single pixel?

The closest I can get is to draw a line that is 2 pixels wide, or do
create another image that's 1x1 with the color of the pixel, then do a
DrawImage to insert that image into the 'master' image...which seems like
a huge waste!

Thanks.

Nov 21 '05 #3
What happens if the page units are set to inches? ;-)

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Rob T" <RT*********@DONTwalchemSPAM.com> schrieb:
[Drawing a single pixel]


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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
What happens if the page units are set to inches? ;-)


I read the article in your FAQ now and learned something new :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Good trick with the -1 for the pen width. Drawing the rectangle worked
fine. you still can't draw a line unless it's more than one pixel long:
objGraphics.DrawLine(New Pen(Color.Black, -1), New Point(5,5), New
Point(5,5)) Doesn't work.

No big deal if the FillRectangle works.......

Thanks guys!

BTW Bob. I adapted your c# graphics editor into a little VB app this week.
It's a bit different from yours now, I you had some good trick in yours that
I was able to adapt. Thanks!
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
What happens if the page units are set to inches? ;-)


I read the article in your FAQ now and learned something new :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Excellent. I love it when people use my code!
--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Good trick with the -1 for the pen width. Drawing the rectangle worked
fine. you still can't draw a line unless it's more than one pixel long:
objGraphics.DrawLine(New Pen(Color.Black, -1), New Point(5,5), New
Point(5,5)) Doesn't work.

No big deal if the FillRectangle works.......

Thanks guys!

BTW Bob. I adapted your c# graphics editor into a little VB app this
week. It's a bit different from yours now, I you had some good trick in
yours that I was able to adapt. Thanks!
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
What happens if the page units are set to inches? ;-)


I read the article in your FAQ now and learned something new :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #7
How different the A-Team could have been if that had been Hannibal's
motto...

"> Excellent. I love it when people use my code!


--
Bob Powell [MVP]
Visual C#, System.Drawing

Nov 21 '05 #8
Careful....you're showing you age!

"Steve McLellan" <sjm AT fixerlabs DOT com> wrote in message
news:On*************@TK2MSFTNGP10.phx.gbl...
How different the A-Team could have been if that had been Hannibal's
motto...

"> Excellent. I love it when people use my code!


--
Bob Powell [MVP]
Visual C#, System.Drawing


Nov 21 '05 #9
I don't know... it was a long running series :-)

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...
Careful....you're showing you age!

"Steve McLellan" <sjm AT fixerlabs DOT com> wrote in message
news:On*************@TK2MSFTNGP10.phx.gbl...
How different the A-Team could have been if that had been Hannibal's
motto...

"> Excellent. I love it when people use my code!


--
Bob Powell [MVP]
Visual C#, System.Drawing



Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bob Sanderson | last post: by
reply views Thread by MC D | last post: by
2 posts views Thread by Bob Palank | last post: by
7 posts views Thread by TomHL | last post: by
13 posts views Thread by Martijn Mulder | last post: by
11 posts views Thread by dongarbage | last post: by
8 posts views Thread by ofiras | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.