2014-09-25 13 views
1

我是ios上的新開發者。我開發一個正常的地方,我使用一些按鈕和屏幕背景圖像。我可以用按鈕和背景截圖。現在我想要拍攝特定對象的屏幕截圖。能有可能在目標C如何在ios中採取特定對象截圖

這是我的代碼

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; 
imageView.layer.zPosition = 14; 
imageView.image = image; 
[self.view addSubview:imageView]; 
+0

特定對象?屏幕上的圖像? – GenieWanted 2014-09-25 12:50:57

+0

從上面我假設你說用戶可以點擊一個按鈕,它會採取一個頁面和背景圖像的屏幕截圖,你問如何拍攝特定UI元素的屏幕截圖? – logixologist 2014-09-25 12:58:37

+0

是的。你是對的。感謝評論@logixologist – Asaduzzaman 2014-09-27 05:03:01

回答

1

是下面提到美國可以採取特定對象的屏幕截圖: -

UIGraphicsBeginImageContextWithOptions(hiddenView.bounds.size, self.view.opaque, 0.0); //In this I have take screenshot of a hiddenView that I have added from IB with a background color anything(in this case it's orange). 
//Replace this hiddenView object with your object of whom you want to take screenshot. 

[hiddenView.layer renderInContext:UIGraphicsGetCurrentContext()]; //Similarly replace hiddenView here with your object. 

UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

NSData*theImageData=UIImageJPEGRepresentation(theImage, 1.0); 
imgView.image = [UIImage imageWithData:theImageData]; //I placed a UIImageView to check and place the screenshot into it as Image ,simply to cross check if I'm getting a right screenshot or not. 
//So you could also remove this line after your have verified that your getting right screen shot. 

別的然後讓我知道。

+0

我不明白什麼是「hiddenView」,以及如何拍攝特定對象的快照,這意味着UIImageView? – Asaduzzaman 2014-09-27 05:22:13

+0

hiddenView是我在演示中放置的UIView,所以我傳遞了該hiddenView的邊界(將它的背景顏色設置爲橙色),並且當我將NSData作爲結果進行交叉檢查時,我使用NSData將圖像和圖像放在一起。有效。此外,我已在我的文章中更新了一些解釋,所以請仔細閱讀。 – nikhil84 2014-09-29 04:20:48

+0

謝謝。我用它來解決我的問題。 @ walle84 – Asaduzzaman 2014-09-29 06:56:14