How to save current screen to iPhone library

Posted: Sunday, January 23, 2011 | Posted by Dipak Mishra | Labels: ,
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!

Share

0 comments:

Post a Comment