472,328 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 12789
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Sanderson | last post by:
I have a number of pages containing tables. Most have background images which have a single pixel border. The tables themselves do not have...
0
by: MC D | last post by:
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...
2
by: Bob Palank | last post by:
Anyone ever try to place one pixel on the drawing surface ? The code below provides two pixels. When x+1 is changed to x, nothing is drawn. So I...
7
by: TomHL | last post by:
hello, - I have a Bitmap Object named: bmp1 - I already have the numerical values of:red,blue and green colors + I have the X and Y...
6
by: Kyle | last post by:
I want to do a single pix update bar instead of the big block that progress bars usually use. I can't seem to find any info on how to do this. ...
13
by: Martijn Mulder | last post by:
I try to define a line with the length of 1 unit (1 pixel) that is, in fact, just a point on the screen. But when I draw it with a wide pen with the...
11
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
8
by: ofiras | last post by:
Hi, I made a "Paint" program, but I couldn't find a method to paint 1 pixel using graphic state ("Graphics g = Graphics.FromHwnd(this.Handle);")...
2
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'm trying to create a QRCode decoder in PHP. I'm not sure if something like this has been created already, but from my searching, I don't think it...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.