How to draw only one pixel on form

C

cty0000

I need to draw only 1 pixel but I can not found out the way...

I tried to use like following in some function
(point1 is Point instance)

Graphics gB = Graphics.FromImage(gBmp);

gB.DrawEllipse(pen.WHITE, point1.X, point1.Y, 1, 1);
gB.DrawRectangle(pen.WHITE, point1.X, point1.Y, 1, 1);
gB.DrawLine(pen.WHITE, point1,point1);

All of above example are not drawing only 1 pixel (looks 4 pixel...)

Someone recommand me drawEllipse or drawLine but the result was not
only 1 pixel...
I tried to find out the solution in web site but I could not find....

How to draw ONLY one pixel?????
 
E

edward.j.stewart

I searched for a long time today to answer this question and finally
found something that works:

System.Drawing.Bitmap bm = new System.Drawing.Bitmap(1,1);
bm.SetPixel(0, 0, color);
graphics.DrawImageUnscaled(bm, x , y);

Creates a new 1x1 bitmap, sets it color, then adds it to your graphics
object. I lost the source where I found this now, but many thanks to
whomever that was!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top