How to save current screen to iPhone library

Here is a quick post, in which I am posting a quick snippet to capture the current screen of iPhone and save it to the phone library. This piece of code will be helpful in generating screen-shot of any iPhone application programmatically.

  1. (void)saveScreen
  2. {
  3. CGRect myRect = [self.view bounds];
  4. UIGraphicsBeginImageContext(myRect.size);
  5. CGContextRef ctx = UIGraphicsGetCurrentContext();
  6. [[UIColor blackColor] set];
  7. CGContextFillRect(ctx, myRect);
  8. [self.view.layer renderInContext:ctx];
  9. UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
  10. UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
  11. UIGraphicsEndImageContext();
  12. }

Please leave your comments here so that I can find out, if you find this snippet useful or not
Enjoy!

2 thoughts on “How to save current screen to iPhone library

  1. Pingback: URL
  2. Enjoyed it says:

    Enjoyed reading this a lot

Leave a Reply

Your email address will not be published. Required fields are marked *