如何对视图进行快照包含GLKView

时间:2016-08-10 11:05:02

标签: ios opengl-es glkview

我有一个viewA,它包含一个GLKView和子视图作为UIImageView。如何将viewA快照到图像?我使用此代码,适用于任何类型的视图,但GLKView

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

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

}

1 个答案:

答案 0 :(得分:0)

它帮助我:

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

并将其绘制到您需要的上下文中,例如:

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