How to snapshot a view contains GLKView

562 Views Asked by At

I have a viewA that contains a GLKView and subviews as UIImageView. How can I snapshot hold of viewA to an image? I'm using this code, work good for any kind of view but GLKView

- (UIImage *) takeSnapshot
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [[UIScreen mainScreen] scale]);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

}
1

There are 1 best solutions below

0
Bogdan Evsenev On

its help me:

GLKView *glView = ...;
UIImage *img = [glView snapshot];

and draw it to context what you need, for example:

CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint point = glView.frame.origin;
[img drawAtPoint:point blendMode:kCGBlendModeNormal alpha:1];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();