0

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

erickson
  • 265,237
  • 58
  • 395
  • 493
Alex1987
  • 9,397
  • 14
  • 70
  • 92

2 Answers2

11

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
  • 923
  • 1
  • 7
  • 16
1

In a nutshell:

CGImageRef screen = UIGetScreenImage();
UIImage *screenImage = [UIImage imageWithCGImage:screen];
diederikh
  • 25,221
  • 5
  • 36
  • 49