views:

91

answers:

1

I need a kind of "screenshot" from everything that's displayed in an UIView. Maybe there's a way to just access the image data that the renderer generated to display the contents on screen?

+3  A: 

The following should work. Depending on what sort of transforms you have defined on the view and layer you might need to apply some sort of rotation.

- (UIImage *)imageForView:(UIView *)view {
  UIGraphicsBeginImageContext(view.frame);
  [view.layer renderInContext: UIGraphicsGetCurrentContext()];
  UIImage *retval = UIGraphicsGetImageFromCurrentImageContext(void);
  UIGraphicsEndImageContext();

  return retval;
}
Louis Gerbarg