@objc func launchCoreML() {
let settings = AVCapturePhotoSettings()
let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first
let previewFormat = [
kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
kCVPixelBufferWidthKey as String: 160,
kCVPixelBufferHeightKey as String: 160
] as [String : Any]
settings.previewPhotoFormat = previewFormat
cameraOutput.capturePhoto(with: settings, delegate: self)
}
I have an error saying:
Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormat'.
I'm using the beta version of Xcode 9.
In beta 4 this got renamed to __availablePreviewPhotoPixelFormat
. I haven't looked at beta 5 yet.
I experienced the same problem after upgrading to Xcode 12.0
It seems that settings.availablePreviewPhotoPixelFormatTypes
has been changed to settings.__availablePreviewPhotoPixelFormatTypes
again in the Final Xcode Release: Version 12.0 (12A7209). I have been using it without the 'rename' for at least 2 years. Thx to @Matthijs Hollemans for the help
EDIT: This is the official response with regards to this change: https://developer.apple.com/forums/thread/86810?answerId=259270022#259270022
This code compiles OK.
let settings = AVCapturePhotoSettings()
guard let previewPixelType = settings.__availablePreviewPhotoPixelFormatTypes.first else { return }
let previewFormat = [
kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
kCVPixelBufferWidthKey as String: 160,
kCVPixelBufferHeightKey as String: 160
]
settings.previewPhotoFormat = previewFormat
output.capturePhoto(with: settings, delegate: self)
var photoSettings: AVCapturePhotoSettings
if #available(iOS 11.0, *) {
photoSettings = AVCapturePhotoSettings.init(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])
} else {
// Fallback on earlier versions
photoSettings = AVCapturePhotoSettings()
if photoSettings.__availablePreviewPhotoPixelFormatTypes.count > 0 {
photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String : photoSettings.__availablePreviewPhotoPixelFormatTypes.first!]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With