Swift版二维码扫描,识别光线强度是否开启手电筒

工作需要写了个二维码扫描的框架,识别光线强度是否开启手电筒,项目地址:https://github.com/GitZhouQi/QRCode

光线识别:

public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {

guard let metadataDict: CFDictionary = CMCopyDictionaryOfAttachments(nil, sampleBuffer, kCMAttachmentMode_ShouldPropagate) else { return }
guard let metadata = metadataDict as? [AnyHashable: Any] else { return }
var brightnessValue: Float = 0
guard let exifMetadata = (metadata[(kCGImagePropertyExifDictionary as String)]) as? [AnyHashable: Any] else { return }
guard let brightness = exifMetadata["BrightnessValue"] as? NSNumber else { return }
brightnessValue = brightness.floatValue
}

你可能感兴趣的:(Swift版二维码扫描,识别光线强度是否开启手电筒)