2014-01-09 23 views
1


我需要找到截圖的子頁面的數量,
考慮:,
1)頁的總高度,1子頁面的
2)高度,
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 

由於

回答

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

謝謝..我還能夠解決同樣使用算術級數: AddedLag =(pageHeight/subpageHeight)*重疊 因此,額外的頁面:= Math.ceiling(AddedLag/subpageHeight) – zeetit

1

你可以用一個簡單的公式:

number = (page_height - overlap)/(subpage_height - overlap) 

如果數字是分數一個(例如5.123)你應該把加起來(5.123到6)。

例如,如果page_height = 100,subpage_height = 20和重疊= 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; 
}