首页 > 解决方案 > 以编程方式创建 ARReferenceImage

问题描述

我正在从数据库中下载图像并希望将它们用作 ARReferenceImage,而不是手动将它们添加到 Xcode 资产文件夹。

代码

    let image = #imageLiteral(resourceName: "mike")
    let cgImage = image.cgImage

    guard let referenceImages = ARReferenceImage.init(cgImage, orientation: .portrait, physicalWidth: 100) else {
        fatalError("Failed to load image")
    }

错误

对成员 'init(_:orientation:physicalWidth:)' 的模糊引用

标签: iosswiftarkit

解决方案


CGImagePropertyOrientation 不支持.portrait请使用以下支持:

public enum CGImagePropertyOrientation : UInt32 {


    case up // 0th row at top,    0th column on left   - default orientation

    case upMirrored // 0th row at top,    0th column on right  - horizontal flip

    case down // 0th row at bottom, 0th column on right  - 180 deg rotation

    case downMirrored // 0th row at bottom, 0th column on left   - vertical flip

    case leftMirrored // 0th row on left,   0th column at top

    case right // 0th row on right,  0th column at top    - 90 deg CW

    case rightMirrored // 0th row on right,  0th column on bottom

    case left // 0th row on left,   0th column at bottom - 90 deg CCW
}

你的代码:

 let referenceImages = ARReferenceImage(cgImage!, orientation: CGImagePropertyOrientation.up, physicalWidth: 100) 

或者

let referenceImages = ARReferenceImage.init(cgImage!, orientation: CGImagePropertyOrientation.up, physicalWidth: 100)

推荐阅读