锁定iOS相机曝光崩溃

时间:2014-12-26 14:50:48

标签: ios objective-c avcapturedevice camera-api

我有以下代码:

-(void) startCameraCapture {
    // start capturing frames
    // Create the AVCapture Session
    session = [[AVCaptureSession alloc] init];

    // create a preview layer to show the output from the camera
    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
    // Specify that the video should be stretched to fill the layer’s bounds.
    previewLayer.videoGravity = AVLayerVideoGravityResize;

    //previewView.frame = CGRectMake(126.0, 164.0, 64.0, 75.0);


    previewLayer.frame = previewView.frame;
    [previewView.layer addSublayer:previewLayer];

    // Get the default camera device
    AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    // get the current settings
    [appDelegate loadSettings];
    [session startRunning];     
}

有没有办法可以锁定相机设备的曝光,只允许屏幕调整到一定的亮度?

很抱歉,如果我没有问这个问题。

谢谢。

编辑:

我尝试添加:

[camera setExposureModeCustomWithDuration:CMTimeMake(1,1) ISO:100 completionHandler:nil];

但这只会导致应用程序在该行崩溃。

1 个答案:

答案 0 :(得分:1)

根据Apple的文档:

如果在未首先使用NSGenericException获取对接收方的独占访问权限的情况下调用此方法,则抛出lockForConfiguration异常:

所以在前面加上这一行:

[camera lockForConfiguration:nil];