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 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);


            

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

我们发现 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)...




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值