1

iSight から写真をキャプチャしようとしています。AVCaptureDevice と AVCaptureSession を設定した後、showCamera 関数を呼び出しても、iSight カメラがオンになってからオフになるだけです。

@IBAction func showCamera(sender: AnyObject) {
    var errorPointer:NSErrorPointer = nil

    let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    let input = AVCaptureDeviceInput(device:device, error:errorPointer)
    let output = AVCaptureStillImageOutput()

    output.outputSettings = [kCVPixelBufferPixelFormatTypeKey : k32BGRAPixelFormat]

    let captureSession = AVCaptureSession()

    captureSession.sessionPreset = AVCaptureSessionPresetPhoto
    captureSession.addInput(input)
    captureSession.addOutput(output)
    captureSession.startRunning()

    let connection = output.connectionWithMediaType(AVMediaTypeVideo)

    output.captureStillImageAsynchronouslyFromConnection(connection, completionHandler: {(sampleBuffer, error) in
        if sampleBuffer != nil {
            let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)

            if (imageBuffer != nil) {
                let rep = NSCIImageRep(CIImage:CIImage(CVImageBuffer:imageBuffer))
                let image = NSImage(size:rep.size)
                image.addRepresentation(rep)
                self.imageView.image = image // Try to see the image
            }
        }
    })
}

何がうまくいかないかについて何か提案はありますか?ありがとう!

4

0 に答える 0