有没有人有幸在 ARKit 项目中截取 ARSKView
的屏幕截图?
我试过这样的:
if let sc = view.snapshotView(afterScreenUpdates: true) {
DispatchQueue.main.async {
UIGraphicsBeginImageContextWithOptions(sc.bounds.size, true, 0.0)
sc.drawHierarchy(in: sc.bounds, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot!, nil, nil, nil)
}
}
但输出的是黑色图像。
在 Apple 的示例中,他们使用的是 ARSCNView
,他们可以在其中调用快照函数,它会自动执行所有操作。
我使用的是 SpriteKit 而不是 SceneKit,所以在 spriteKit 中没有快照方法。
最佳答案
我在
ARSKView
上使用drawHeirarchy(in:afterScreenUpdates:)
时也出现黑屏另一种对我来说失败的方法:使用 ARSession 属性
(ARFrame *)currentFrame
- 将像素缓冲区capturedImage
转换为UIImage
但这只是显示真实世界的图像,不包括 Sprite 。对我有用的只是从 View Controller View 而不是
ARSKView
截取屏幕截图。仍然可以切换到 SceneKit,因为您仍然可以在
SCNNode
上使用 SpriteKit 作为 Material 。 SceneKit 还附带快照等好东西。还有像 ARVideoKit 这样的开源实现 https://github.com/AFathi/ARVideoKit还有
关于ios - ARSKView 快照 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46014695/