Tuesday, July 21, 2009

Take current screen shot

Code for getting the current screen shot as UIImage

//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

CGRect screenRect = [[UIScreen mainScreen] bounds];

UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();

[[UIColor blackColor] set];

CGContextFillRect(ctx, screenRect);

[self.view.layer renderInContext:ctx];

UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();

UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);

UIGraphicsEndImageContext();

No comments:

Post a Comment