views:

404

answers:

2

Hi guys,

I'm looking for a way to write the contents of the screen to an image. Any idea how to achieve that? Does it involve using Quartz?

Thanks

+2  A: 

In a nutshell:

CGImageRef screen = UIGetScreenImage();
UIImage *screenImage = [UIImage imageWithCGImage:screen];
Diederik Hoogenboom
Except that's not in the API documentation. Apple may not allow an application that uses an undocumented API in the App Store.
Stephen Darlington
+6  A: 

Add this code to your UIViewController to create a screen dump of its UIView.

// create screen dump of the view of this view controller
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// save image to photos
UIImageWriteToSavedPhotosAlbum(screenShot, self, nil, nil);
Jens Utbult