关于对Rectangle的边界处理

来源:互联网 发布:中英文说话翻译软件 编辑:程序博客网 时间:2024/04/28 20:23

今天很奇怪地发现一个问题,现象是:
1. 当采用一个与Rectangle无关的box作为ROI缩放时,需要用
Org.left = ROI.left + ROUND(Zoom.left*fInvW);
Org.top = ROI.top + ROUND(Zoom.top*fInvH);
lOrgW = ROUND(lZoomW*fInvW);
lOrgH = ROUND(lZoomH*fInvH);
Org.right = Org.left + lOrgW;
Org.bottom = Org.top + lOrgH;

而如果采用一个与Rectangle相关的box作为ROI缩放,则需要用
Org.left = ROI.left + ROUND(Zoom.left*fInvW);
Org.top = ROI.top + ROUND(Zoom.top*fInvH);
Org.right = ROI.left + ROUND(Zoom.right*fInvW);
Org.bottom = ROI.top + ROUND(Zoom.bottom*fInvH);

通过深入debug发现,这种现象产生的原因并不是因为是否相关,而是因为在获取ROI时,需要等比例地缩放。

不然,来回计算得到的值会产生漂移。

并且,当采用等比例缩放时,采用第二种写法也要优于第一种写法。

 

原创粉丝点击