ios - ARSKView 快照 iOS

标签 ios sprite-kit augmented-reality arkit

有没有人有幸在 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/

相关文章:

后台崩溃 - Sprite-Kit 相关

ios - 定义 SCNNode 的位置

android - 将可渲染节点(相同的旋转、位置和比例)替换为 Sceneform sdk 中的另一个可渲染节点

algorithm - 魔方扫描算法

restkit 中的 ios NSDateFormatter

ios - iPhone 5 模拟器返回错误的屏幕尺寸

ios - 释放触摸时 UISlider 过于敏感

objective-c - subview 上无法识别手势

swift - 解码保存后 iOS SpriteKit 碰撞检测失败

swift - 动画后如何去除SKTexure