3

我想在这里捕捉图像:

var stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]

[...] 

if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) {
     videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
     println("enabled = \(videoConnection.enabled)") //enabled = true
     println("active = \(videoConnection.active)") //active = true
     stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {
          (sampleBuffer, error) in
          if error != nil {
               println(error)
          }
     })
}

它在大多数情况下都能完美运行!

但有时我在调用时遇到错误captureStillImageAsynchronouslyFromConnection

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn't be completed." 
UserInfo=0x14682110 {NSLocalizedDescription=The operation couldn't be completed., 
NSUnderlyingError=0x1676be30 "The operation couldn't be completed.
(OSStatus error -16400.)", 
NSLocalizedFailureReason=An unknown error has occured (-16400)}

我只是想预计会发生此错误。我尝试过测试videoConnection.enabledvideoConnection.active但两者似乎都与错误无关......

在拍摄照片之前我需要检查什么以确保一切正常?

4

1 回答 1

5

我也收到了与您相同的错误消息。经过多次调试,我意识到我在拍照之前无意中停止了捕获会话。仔细检查.running您的属性AVCaptureSession是否为true.

于 2015-11-14T21:30:58.840 回答