iOS编程手电筒功能不强

时间:2015-07-06 09:24:38

标签: ios flash camera

要使用此代码打开手电筒和手电筒:

if ([device hasTorch]) {
    [device lockForConfiguration:nil];
    [device setTorchMode: on ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];
    [device setFlashMode: on ? AVCaptureFlashModeOn : AVCaptureFlashModeOff];
    [device setFocusMode:AVCaptureFocusModeAutoFocus];
    [device unlockForConfiguration];
}

但是如果你将它与原生相机应用程序进行比较,你会发现当拍摄照片时本机手电筒更强大 有没有办法在拍摄类似于原生相机闪光灯的照片时强大它?

2 个答案:

答案 0 :(得分:0)

您可以使用以下代码更新代码:

- (void)setTorchToLevel:(float)torchLevel
{
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([device hasTorch]) {
        [device lockForConfiguration:nil];
        if (torchLevel <= 0.0) {
            [device setTorchMode:AVCaptureTorchModeOff];
        }
        else {
            if (torchLevel >= 1.0)
                torchLevel = AVCaptureMaxAvailableTorchLevel;
            BOOL success = [device setTorchModeOnWithLevel:torchLevel   error:nil];
        }
        [device unlockForConfiguration];
    }
}

希望这会对你有所帮助。

答案 1 :(得分:0)

尝试添加以下代码。

[device setTorchModeOnWithLevel:AVCaptureMaxAvailableTorchLevel error:nil];