Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Capture an image of a view not yet displayed
       
back

// Capture an image of a view, inside of a ViewController with Xib, not yet displayed. 
// use:
// CaptureViewController *viewController = [[CaptureViewController alloc] initWithNibName:@"CaptureViewController" bundle:nil];
// [viewController loadView];
// UIImage *img = [viewController capture];
//
- (UIImage*)capture {
    
    UIGraphicsBeginImageContext(self.view.bounds.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    [self.view.layer renderInContext:context];
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com