简体   繁体   中英

iphone save multiple views screenshot

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:UIGraphicsGetCurrentContext()];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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