我需要查找截图的子页面数量。,
鉴于:,
1)页面总高度,
2)1个子页面的高度,
3)每个连续的屏幕截图高度与上面的屏幕重叠" 5"像素
Ex : Page height = 100 px
1 Screen height (subpage) = 20px
Then,
1st screenshot : 0px to 20 px
2nd screenshot : 15px to 35px.. and so on
由于
答案 0 :(得分:1)
private int GetSubPageCount(int heightOfPage)
{
int heightOfSubPage = 20;
int overlap = 5;
// that gives you count of completely filled sub pages
int subPageCount = (heightOfPage - overlap) / (heightOfSubPage - overlap);
// if last sub page is not completely filled, than add one page
if ((heightOfPage - overlap) % (heightOfSubPage - overlap) > 0)
subPageCount++;
return subPageCount;
}
或者您可以使用舍入到最大整数值的浮点数,该整数值大于或等于完全填充的子页数:
private int GetSubPageCount(int heightOfPage)
{
int heightOfSubPage = 20;
int overlap = 5;
return (int)Math.Ceiling((double)(heightOfPage - overlap) / (heightOfSubPage - overlap));
}
答案 1 :(得分:1)
您可以使用简单的公式:
number = (page_height - overlap) / (subpage_height - overlap)
如果数字是小数一个(例如5.123),你应该将其整理(5.123到6)。
例如,如果page_height = 100,subpage_height = 20且overlap = 5,我们可以推导出
number = (100 - 5) / (20 - 5) = 6.333333
number = 7 (rounded up)
示例代码:
public static int SubPageCount(int pageHeight, int height, int overlap) {
int result = (pageHeight - overlap) / (height - overlap);
// If there's a fractional part - i.e. remainder in not 0
// one should round the result up: add 1
if (((pageHeight - overlap) % (height - overlap)) != 0)
result += 1;
return result;
}