Undesired anti-aliasing when drawing bitmap on a window

前端 未结 1 1735
Happy的楠姐
Happy的楠姐 2020-12-07 03:47

I\'m rendering an image into a System.Drawing.Bitmap and subsequently drawing it into a window, however I can see that the edges are being anti-aliased. How do prevent this?

1条回答
  •  伪装坚强ぢ
    2020-12-07 04:31

    Set the InterpolationMode property to NearestNeighbor and PixelOffsetMode to None.

    pea.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
    pea.Graphics.PixelOffsetMode = PixelOffsetMode.None; // or PixelOffsetMode.Half
    

    Drawing the bitmap unscaled is best. In which case you probably want to use the ClientSize.Width and Height properties to initialize the bitmap. Odds are good that you are making the bitmap too large right now by including the form's border and caption. I can't tell from the snippet.

    0 讨论(0)
提交回复
热议问题