I render a png on a empty custom User Control like this:
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
var drawRect = new Rectangle(0, 0, (int)(imgWidth* ImageScale), (int)(imgHight* ImageScale));
e.Graphics.DrawImageUnscaledAndClipped(myImage, drawRect);
So that I can see properly the pixels without antialiasing and scale the image.
Through the MouseMove event I save the mouse position on a property of the control and then I show the pixel on which the mouse is currently on, like this:
e.Graphics.FillRectangle((Brush)Brushes.Black, _mousePosition.X, _mousePosition.Y, (int)ImageScale, (int)ImageScale);
I have two problem:
- the pixel is of the right size, but its position (when rendered) is continuous and do not follow the pixel grid as I wanted
- I had to insert Invalidate() at the end of the MouseMove event to force the pixel rendering, maybe there is an better way to do this