以编程方式创建 ARReferenceImage
Create ARReferenceImage programmatically
我正在从数据库下载图像并希望将它们用作 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:)'
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)
CGImagePropertyOrientation
没有名为 .portrait
.
的成员
根据documentation有.up
、.upMirrored
、.down
、.downMirrored
、.leftMirrored
、.right
, .rightMirrored
, .left
。如果您在初始化程序中使用其中之一,它应该可以工作。
例如:
let referenceImage = ARReferenceImage(cgImage, orientation: .up, physicalWidth: 100)
我正在从数据库下载图像并希望将它们用作 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:)'
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)
CGImagePropertyOrientation
没有名为 .portrait
.
根据documentation有.up
、.upMirrored
、.down
、.downMirrored
、.leftMirrored
、.right
, .rightMirrored
, .left
。如果您在初始化程序中使用其中之一,它应该可以工作。
例如:
let referenceImage = ARReferenceImage(cgImage, orientation: .up, physicalWidth: 100)