473,886 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12973
"Rob T" <RT*********@DO NTwalchemSPAM.c om> schrieb:
[Drawing a single pixel]


\\\
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.Fill Rectangle( _
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*********@DO NTwalchemSPAM.c om> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
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******** ********@tk2msf tngp13.phx.gbl. ..
"Rob T" <RT*********@DO NTwalchemSPAM.c om> schrieb:
[Drawing a single pixel]


\\\
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.Fill Rectangle( _
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@_spamkille r_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.Dra wLine(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******** ******@tk2msftn gp13.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkille r_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*********@DO NTwalchemSPAM.c om> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l...
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.Dra wLine(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******** ******@tk2msftn gp13.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkille r_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******** *****@TK2MSFTNG P10.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*********@DO NTwalchemSPAM.c om> wrote in message
news:e8******** ******@TK2MSFTN GP09.phx.gbl...
Careful....you' re showing you age!

"Steve McLellan" <sjm AT fixerlabs DOT com> wrote in message
news:On******** *****@TK2MSFTNG P10.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
12030
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 borders. For various reasons, I have to create one table without an image, so the border must be defined by the table. However, the table border does not look exactly like the single pixel one in the images. It appears to have some shading. I have tried various CSS elements but have not been able...
0
1262
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 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)
2
6112
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 guess the shortest line is two pixels. Graphics g = e.Graphics; // Grt a drawing Surface Pen redPen = Pens.Red; int x = 50; int y =50; g.DrawLine(redPen, x, y, x+1, y);
7
3607
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 cordinates. How do I set the pixel value via safe code on the bmp1 object? (the pixel location based on the X & Y values and it's color based on the red,blue and green values the I already have)
6
2523
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. Thanks in advance for any help, Kyle
13
2401
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 appropriate StartCap and EndCap (Round), it will appear as a dot. I can think of a way to define a 1-pixel long line but it is ugly and clumsy. I subtract .5 from the given pixel's X and Y coordinate for the first System.Drawing.PointF structure, and add .5 to the other PointF stucture. It...
11
11288
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
3553
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);") How can I paint 1 pixel? I guess I can make a Bitmap, change one pixel color and show it, but I'm sure there is another way of doing it. Please help, Ofir.
2
4726
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 has. If you don't know what QRCodes are, they're basically 2D barcodes that let you store a lot of information. Here's an example: http://infectionist.com/misc/qrcode/php/qr_img.php?d=0123456789&e=M&s=6&v=1 (mouse over for the whole thing) This code is simple, just contains the text...
0
9956
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10770
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4627
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.