如何在ios中拍摄特定对象的截图

时间:2014-09-25 12:43:18

标签: ios

我是ios的新开发者。我开发了一个正常,我使用一些按钮和屏幕背景图像。我可以用按钮和背景截取屏幕截图。现在我想采取屏幕截图特定对象。可以在客观的c

这是我的代码

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];

1 个答案:

答案 0 :(得分: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.

其他任何事都让我知道。