0

I have a panel control and a bitmap with the same size. When I resize the panel I want the bitmap to be drawn on it. I use DrawImage(Image, Int32, Int32, Int32, Int32)

This is the panel (Canvas) Paint Event

private void Canvas_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(image, 0, 0, Canvas.Width, Canvas.Height);
        }

But the image moves a bit. Looks like the method draws it in (-0.5, -0.5) instead of (0, 0)

Original picture

Bitmap on panel (Red pixel is cut and dark grey border appears)

How to fix it?

  • How is the Canvas on the form? – Jeroen van Langen Jun 05 '22 at 18:55
  • What happens you you set this Bitmap as the `BackgroundImage` of your Panel? Also setting `BackgroundImageLayout` to what appears to be `Stretch`. -- See also `InterpolationMode = InterpolationMode.NearestNeighbor` and `PixelOffsetMode = PixelOffsetMode.Half` – Jimi Jun 05 '22 at 19:10
  • Some notes about InterpolationMode and PixelOffsetMode [here](https://stackoverflow.com/a/54726707/7444103) – Jimi Jun 05 '22 at 19:18
  • Thank You! It happened because of PixelOffsetMode. – NikitaBegginer2005 Jun 10 '22 at 11:22

0 Answers0