相机永远不会激活LowLightBoost

时间:2013-10-25 08:23:40

标签: ios6 camera

我的iPhone V上运行了以下代码:

// Create the capture device
camera = [CameraManager cameraWithPosition:AVCaptureDevicePositionBack];
if (camera.lowLightBoostSupported) {
    if ([camera lockForConfiguration:nil]) {
        camera.automaticallyEnablesLowLightBoostWhenAvailable = YES;
        [camera unlockForConfiguration];
    }
}

但是即使我把背面的设备放在桌子上,所以lowLightBoost永远不会激活,因此预览图像是黑色的。

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{

    NSLog(@"LowLight active: %@ Camera lowlightWhenAvailable: %@",camera.isLowLightBoostEnabled ? @"true": @"false",camera.automaticallyEnablesLowLightBoostWhenAvailable ? @"true": @"false");

给了我

2013-10-25 10:21:53.179 aCoDriver [1019:668f] LowLight active:false相机低亮时可用:真实 2013-10-25 10:21:53.429 aCoDriver [1019:668f] LowLight active:false相机低亮时可用:真实 2013-10-25 10:21:53.679 aCoDriver [1019:668f] LowLight active:false相机低亮时可用:真实 2013-10-25 10:21:53.929 aCoDriver [1019:668f] LowLight active:false相机低亮时可用:真

1 个答案:

答案 0 :(得分:1)

从你的代码中,我不确定为什么那样行不通。如果它有帮助,这就是我的工作 - 以及注册通知,这样你就可以准确地看到低光增强开关自动的时间(例如,如果你指着相机一个明亮的灯光,然后平放在它上面)在桌子上,您应该收到一条通知,指示低光增强开启)。这在iOS 6/7中非常适合我:

AVCaptureDevice *device = _stillCamera.inputCamera;
NSError *error;

if(device.lowLightBoostSupported) {
    // NSLog(@"low light is supported");

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    BOOL boostEnabled = [prefs boolForKey:@"lowLightBoostEnabled"];

    if ([device lockForConfiguration:&error]) {
        device.automaticallyEnablesLowLightBoostWhenAvailable = boostEnabled;

        [device unlockForConfiguration];
    }

    // register as an observer of changes to lowLightBoostEnabled
    [device addObserver:self forKeyPath:@"lowLightBoostEnabled" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
}


// for observing changes to _stillCamera.inputCamera.lowLightBoostEnabled
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    if ([keyPath isEqual:@"lowLightBoostEnabled"]) {

        NSLog(@"lowLightBoostEnabled changed");

        NSNumber *boostIsActiveValue = [change objectForKey:NSKeyValueChangeNewKey];

        BOOL boostIsActive = boostIsActiveValue.boolValue;

        NSLog(@"is low light boost currently active: %d", boostIsActive);
    }
}