priore

Capture an image of a view not yet displayed

Jul 9th, 2015
841
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Capture an image of a view, inside of a ViewController with Xib, not yet displayed.
  2. // use:
  3. // CaptureViewController *viewController = [[CaptureViewController alloc] initWithNibName:@"CaptureViewController" bundle:nil];
  4. // [viewController loadView];
  5. // UIImage *img = [viewController capture];
  6. //
  7. - (UIImage*)capture {
  8.    
  9.     UIGraphicsBeginImageContext(self.view.bounds.size);
  10.     CGContextRef context = UIGraphicsGetCurrentContext();
  11.    
  12.     [self.view.layer renderInContext:context];
  13.    
  14.     UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  15.     UIGraphicsEndImageContext();
  16.    
  17.     return img;
  18. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×