swift开发二维码扫描相机感光

  func initScanView(){
        let lightOutput = AVCaptureVideoDataOutput()
        lightOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main)
       if (self.scanSession?.canAddOutput(lightOutput!))! {
            self.scanSession?.addOutput(lightOutput!)
     }
}

// AVCaptureVideoDataOutputSampleBufferDelegate 代理方法
 func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
        let metadataDic = CMCopyDictionaryOfAttachments(nil, sampleBuffer, kCMAttachmentMode_ShouldPropagate)
        let metadata = NSDictionary.init(dictionary: metadataDic as! [AnyHashable : Any], copyItems: true)
        let exifMetadata:NSDictionary = NSDictionary.init(dictionary: metadata.object(forKey: kCGImagePropertyExifDictionary as String) as! [AnyHashable : Any], copyItems: true)
        let brightnessValue:CGFloat = exifMetadata[kCGImagePropertyExifBrightnessValue] as! CGFloat
   // 你的操作
    }

你可能感兴趣的:(swift开发二维码扫描相机感光)