1

我的 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 相机 lowlightWhenAvailable: true 2013-10-25 10:21:53.429 aCoDriver [1019:668f] LowLight active: false Camera lowlightWhenAvailable: true 2013- 10-25 10:21:53.679 aCoDriver [1019:668f] LowLight active: false 相机 lowlightWhenAvailable: true 2013-10-25 10:21:53.929 aCoDriver [1019:668f] LowLight active: false 相机 lowlightWhenAvailable: true

4

1 回答 1

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);
    }
}
于 2013-10-25T14:03:47.253 回答