Graphics DrawLine 坐标值很大时出现的异常



            Graphics gfx = e.Graphics;
            int x = 150;
            int y = 8380000;
            gfx.DrawLine(new Pen(Color.Red, 1), x, x, x + 10, y);
            x = 150;
            y = 8388608 -1;

            gfx.DrawLine(new Pen(Color.Blue, 1), x + 10, x, x + 20, y);

Graphics DrawLine 坐标值很大时出现的异常_第1张图片


 Graphics gfx = e.Graphics;
            int x = 150;
            int y = 8380000;
            gfx.DrawLine(new Pen(Color.Red, 1), x, x, x + 10, y);
            x = 150;
            y = 8388608 +1;
            gfx.DrawLine(new Pen(Color.Blue, 1), x + 10, x, x + 20, y);

Graphics DrawLine 坐标值很大时出现的异常_第2张图片
            

发现坐标值太大时,发生反方向,什么原因??

我们发现 8388608是Graphic的ClipBound的宽度和高度

  • My first thought is that as y is really way off the actual bitmap bounds you are pushing the limits too far here. Actually I gave a look at gfx.ClipBounds.Top and found this is 8388608/2. So it's likely your very high y value is truncated in a way that gives either a negative value sligthly above gfx.ClipBounds.Bottom or a positive value slightly below gfx.ClipBounds.Top.

    You have (or had ?) something similar in DirectX that is you could use coordinates way off the actual size of a render target but you still had a high value limit (I believe that if you goes past this value, it fails).

    So just try to avoid using way off values when it's easy to do otherwise (or check against ClipBounds if you can't do otherwise)...



你可能感兴趣的:(C#,graphic,坐标值太大)