我正在从数据库下载图像,并希望将它们用作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:)'
的模糊引用答案 0 :(得分:2)
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)
答案 1 :(得分:2)
CGImagePropertyOrientation
没有名为.portrait
的成员。
根据documentation,它有.up
,.upMirrored
,.down
,.downMirrored
,.leftMirrored
,.right
,{ {1}},.rightMirrored
。如果你在初始化程序中使用其中一个,它应该可以工作。
例如:
.left