简体   繁体   English

如何在iOS中获取特定的对象截图

[英]how can take specific object screenshot in ios

i am new developer on ios. 我是ios上的新开发人员。 i develop a normal where i use some button and screen background image. 我在使用一些按钮和屏幕背景图像的情况下开发了普通图像。 i can take screenshot with button and background. 我可以使用按钮和背景截图。 now i want to take screen shot specific object. 现在我想拍摄特定对象的屏幕截图。 can it possible in objective c 在目标c中可以吗

this is my code 这是我的代码

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

Yes u can take screen shot of specific object as mentioned below:- 是的,您可以如下所述对特定对象进行屏幕截图:

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.

Anything else then let me know. 然后让我知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM