开发者

iphone save multiple views screenshot

开发者 https://www.devze.com 2023-01-07 10:38 出处:网络
I have an UIImagePickerController to which I add some subviews that contain images. I need to save the whole content as an image, but fail to do this.

I have an UIImagePickerController to which I add some subviews that contain images. I need to save the whole content as an image, but fail to do this.

For saving the content of the context i use the following code

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

It works for the UIImagePickerController but if i add subviews it stops at the

[self.view.layer renderInContext:UIGraphic开发者_开发百科sGetCurrentContext()];

line, without any error in the console, just quits the app.

Thanks!


If you are trying to grab everything on the screen in your screen shot, I found this on stack overflow:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It will grab everything on the window.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消