MxABC/LBXScan

晚上扫描会自动感光打开手电筒吗

Opened this issue · 1 comments

晚上扫描会自动感光打开手电筒吗

这个很简单,可以自己监听代理方法。

具体是这样的:(brightnessValue 值代表光线强度,值越小代表光线越暗)

`
@Property (nonatomic, strong) AVCaptureVideoDataOutput *videoDataOutput;
// 创建摄像数据输出流,用于识别光线强弱
_videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];

/// MARK: Defines an interface for delegates of AVCaptureVideoDataOutput to receive captured video sample buffers and be notified of late sample buffers that were dropped.
//
/// MARK: 亮度变化

  • (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
    NSDictionary *metadata = [[NSDictionary alloc] initWithDictionary:(__bridge NSDictionary *)metadataDict];
    CFRelease(metadataDict);
    NSDictionary *exifDictionary = [metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary];
    float brightness = [[exifDictionary objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue];
    if (brightness > 0) {
    // 光线明亮,隐藏按钮
    [self.maskView hideLightButton];
    } else {
    // 光线昏暗,显示按钮
    [self.maskView showLightButton];
    }

}
`