views:

33

answers:

1

Hi,

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!

A: 

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.

dredful