Drawing A Pixel

A

Abby Brown

Hi,

I need to draw a line graph a pixel at a time. .Net (GDI+?) doesn't have
Graphics.DrawPixel function so I use Graphics.DrawRectangle(MyPen, X, Y, 1,
1). However, the graph uses a transform so that for small scale values the
rectangle takes many pixels even with a pen width of zero (0).

How do you draw a pixel without scaling applied?

Thanks,
Gary
 
P

Peter Duniho

Hi,

I need to draw a line graph a pixel at a time. .Net (GDI+?) doesn't have
Graphics.DrawPixel function so I use Graphics.DrawRectangle(MyPen, X, Y,
1,
1). However, the graph uses a transform so that for small scale values
the
rectangle takes many pixels even with a pen width of zero (0).

How do you draw a pixel without scaling applied?

If you look at the documentation, you'll find that the Graphics class has
a wide variety of drawing options:

-- SetPixel() for drawing individual pixels
-- DrawLine() for drawing lines between points
-- DrawRectangle() for drawing boxes (i.e. "rectangles").

Pete
 
A

Abby Brown

Peter Duniho said:
If you look at the documentation, you'll find that the Graphics class has
a wide variety of drawing options:

-- SetPixel() for drawing individual pixels
-- DrawLine() for drawing lines between points
-- DrawRectangle() for drawing boxes (i.e. "rectangles").

Pete

The Graphics class does not have a "SetPixel," only Bitmap does.
Line widths in DrawLine and DrawRectangle both scale with the transform.
I need something that won't scale.

Gary
 
F

Fred Mellender

I had a similar problem using WPF. I made each point a circle with radius
2. Then I applied 1/scaleTransform
to the circle. When the panel's transform was applied the two scalings got
me back to a 2-pixel radius. Maybe something similar will work for
Windows.Forms.
 
P

Peter Duniho

The Graphics class does not have a "SetPixel," only Bitmap does.

Sorry, you're right...I should have been clearer about the distinction
between a Graphics instance you get from a Bitmap and the Bitmap itself.
Line widths in DrawLine and DrawRectangle both scale with the transform.
I need something that won't scale.

You have at least a couple of options. I have successfully used the
approach Fred mentions; basically, pre-scale your line widths to account
for the scaling it will undergo when transformed again.

Alternatively, draw the line into an untransformed bitmap an appropriate
size to be composited with your destination image. Depending on the order
of composition and where it's actually done, you may find that you still
need to effectively pre-scale the drawing of the image so that it comes
out the right size in the destination.

Personally, I think that simply pre-scaling the line width is easiest, but
you can try other approaches if you think they would work better in your
given context.

Pete
 
J

Jeff Johnson

I need to draw a line graph a pixel at a time. .Net (GDI+?) doesn't have
Graphics.DrawPixel function so I use Graphics.DrawRectangle(MyPen, X, Y,
1, 1). However, the graph uses a transform so that for small scale values
the rectangle takes many pixels even with a pen width of zero (0).

How do you draw a pixel without scaling applied?

http://www.bobpowell.net/pixel_dot.htm

Cross-post questions like this to microsoft.public.dotnet.framework.drawing,
please. We could use a little life over there....
 
A

Abby Brown

How do you draw a pixel without scaling applied?


Thanks to those who responded. Both the bitmap and "unscale" approach work.
For this application it is sufficient to forego the transform and scale the
Y value explicitly. However, I wanted to get some experience using
transforms. Why a function so simple and obvious is missing is a puzzlement.

Gary
 

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