0

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

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

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

}
4

1 回答 1

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();
于 2016-11-25T07:07:20.840 回答