huggie
huggie

Reputation: 18247

iPhone screen capture for a view

On iphone, is it possible to "screen capture" an UIView and all its subview? If it is possible, how?

Upvotes: 6

Views: 2274

Answers (1)

vikingosegundo
vikingosegundo

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

Related Questions