Pixel behaviour of FillRectangle and DrawRectangle

前端 未结 3 1345
挽巷
挽巷 2020-12-01 21:26

nearly every time I use Graphics.DrawRectangle or Graphics.FillRectangle (the int versions) I seem to miss the pixels on the right and

3条回答
  •  [愿得一人]
    2020-12-01 21:58

    The rectangle in both of the Graphics methods in your question is bounded by (x, y) in the upper left and (x + width - 1, y + height - 1) in the lower right. This is a consequence of specifying width and height, rather than the lower right point.

    When you're calculating the width and height from two points, you have remember to include the origin pixel by adding 1 to the difference.

    For example, say you want to fill a Rectangle from point (5, 5) to point (10, 20). The width of the rectangle is 6, not 5. The height of the rectangle is 16, not 15.

提交回复
热议问题