【发布时间】:2014-01-07 00:35:08
【问题描述】:
有谁知道如何将完整的SKView 或SKScene“快照”到NSImage 中?
我们已经能够使用textureFromNode API 从一个节点及其所有子节点创建一个SKTexture。但到目前为止,我们还没有找到一种方法来将图像数据提取到NSImage 中。我们正在构建一个混合的 Cocoa / SpriteKit 应用程序,我们需要在其中提取场景的小缩略图。
同样,这在 iOS 上似乎是可能的(获得UIImage)使用drawViewHierarchyInRect:
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
但是如何在 Cocoa 和 NSImage 上执行此操作?帮助。
【问题讨论】:
-
这就是你要找的东西:stackoverflow.com/questions/3251261/…
-
不,您提到的链接不适用于基于 OpenGL 的视图(请参阅其中的 cmets),SKViews 就是这种情况。
标签: objective-c macos cocoa sprite-kit skview