2014-02-10 48 views
0

我正在iOS應用程序中,我需要捕捉視圖並將MMS發送給特定的人。它所有的工作都很好。但是我面臨的問題是捕獲哪些不可見(更多解釋我附加圖像)。如何獲取ios中隱形部分的屏幕截圖?

enter image description here

我收到這是visible.How解決問題的視圖的屏幕截圖?有沒有辦法達到我的要求?我所得到的圖像是

enter image description here

我使用的代碼採取截圖

UIGraphicsBeginImageContext(webview_pdf.bounds.size); 
[webview_pdf.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *pdfImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

良好的建議是appreciable.Thanks提前!

回答

0

您需要創建另一個視圖,它是內容的完整大小。您可以將此視圖添加到屏幕外,然後按照您在此處所做的相同方式進行捕獲。它被切斷的原因是因爲該視圖僅顯示了該部分內容。

+0

以及好的建議兄弟 – iSwaroop

+0

但我有一個doubt..Does如果有無限的記錄,它的工作原理? @ CW0007007 – iSwaroop

+0

創建視圖可能需要很長時間。它會適用於任何大小的內容。只需在屏幕外創建另一個視圖容器。將高度設置爲您的內容的高度。然後將該視圖保存爲n圖像。 – CW0007007

1

終於找到了解決這個

+ (UIImage *) imageFromWebView:(UIWebView *)view 
{ 
    // tempframe to reset view size after image was created 
    CGRect tmpFrame = view.frame; 

    // set new Frame 
    CGRect aFrame = view.frame; 
    aFrame.size.height = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height; 
    view.frame = aFrame; 

    // do image magic 
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]); 

    CGContextRef resizedContext = UIGraphicsGetCurrentContext(); 
    [view.layer renderInContext:resizedContext]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    // reset Frame of view to origin 
    view.frame = tmpFrame; 
    return image; 
} 
+0

好的解決方案:) – Vidhyanand

+0

當用代碼回答問題時,請確保代碼格式正確,因爲它使得閱讀很難如果不是。 – Popeye