カスタムカメラの使用に取り組んでおり、最近、Swift 3 とともに Xcode 8 ベータにアップグレードしました。
var stillImageOutput: AVCaptureStillImageOutput?
ただし、次の警告が表示されます。
'AVCaptureStillImageOutput' は iOS 10.0 で廃止されました: 代わりに AVCapturePhotoOutput を使用してください
これはかなり新しいものなので、これに関する情報はあまりありません。これが私の現在のコードです:
var captureSession: AVCaptureSession?
var stillImageOutput: AVCaptureStillImageOutput?
var previewLayer: AVCaptureVideoPreviewLayer?
func clickPicture() {
if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo) {
videoConnection.videoOrientation = .portrait
stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (sampleBuffer, error) -> Void in
if sampleBuffer != nil {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
let dataProvider = CGDataProvider(data: imageData!)
let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: .defaultIntent)
let image = UIImage(cgImage: cgImageRef!, scale: 1, orientation: .right)
}
})
}
}
を調べてみましたAVCapturePhotoCaptureDelegate
が、使い方がよくわかりません。誰もこれを使用する方法を知っていますか? ありがとう。