Reputation: 40339
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?
Upvotes: 0
Views: 143
Reputation: 43452
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;
}
Upvotes: 3