【问题标题】:How to snapshot a view contains GLKView如何对包含 GLKView 的视图进行快照
【发布时间】:2017-09-22 11:23:08
【问题描述】:

我有一个 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;

}

【问题讨论】:

    标签: ios opengl-es glkview


    【解决方案1】:

    它帮助我:

    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();
    

    【讨论】:

      猜你喜欢
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      相关资源
      最近更新 更多