gpt4 book ai didi

swift - 类型 'AVCapturePhotoOutput' 的值没有成员 'captureStillImageAsynchronously'

转载 作者:行者123 更新时间:2023-11-28 14:47:03 24 4
gpt4 key购买 nike

请帮我重构这段代码,它不起作用,我在互联网上搜索但没有找到任何解决方案。我不能自己重构它。

这一行:

imageOutput.captureStillImageAsynchronously(from: connection) { (sampleBuffer, error) -> Void in

抛出这个错误:

Value of type 'AVCapturePhotoOutput' has no member 'captureStillImageAsynchronously'

  imageOutput.captureStillImageAsynchronously(from: connection) { (sampleBuffer, error) -> Void in
if (sampleBuffer == nil || error != nil) {
DispatchQueue.main.async {
completion(nil, error)
}
return
}

guard let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer!, previewPhotoSampleBuffer: nil) else {
DispatchQueue.main.async {
completion(nil, StillImageError.noData)
}
return
}

guard let image = UIImage(data: data) else {
DispatchQueue.main.async {
completion(nil, StillImageError.noImage)
}
return
}

var saver = ImageSaver()

.onSuccess { image, assetId in

completion(assetId, nil)

}
.onFailure { error in

}
saver = saver.save(image, filter: nil)

}

最佳答案

captureStillImageAsynchronously(from:completionHandler:)AVCaptureStillImageOutput 的函数,而不是 AVCapturePhotoOutput

由于 AVCaptureStillImageOutput 自 iOS 10 起已被弃用,因此您应该改用 AVCapturePhotoOutput,就像您在代码中所做的那样。它有一个具有相同用例的函数:capturePhoto(with:delegate:)

有关 AVCapturePhotoOutput 用法的更多信息,check out this question .

关于swift - 类型 'AVCapturePhotoOutput' 的值没有成员 'captureStillImageAsynchronously',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50167957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com