Reputation: 18247
On iphone, is it possible to "screen capture" an UIView and all its subview? If it is possible, how?
Upvotes: 6
Views: 2274
Reputation: 52237
I found this, but I haven't tried it myself.
Here you find the used -renderInContext
.
I transformed the code above to a category on UIView.
call it like this: [aView saveScreenshotToPhotosAlbum];
#import <QuartzCore/QuartzCore.h>
- (UIImage*)captureView {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum {
UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);
}
Upvotes: 9