AvFoundation在Iphone中从相机拍摄黑色图像

时间:2016-01-20 11:22:45

标签: ios iphone avfoundation

我是iPhone的新手,并使用AVFoundation制作了一个用于拍摄照片的演示。我正在拍摄5张最大图像,但问题是当我拍摄第一张图像时,它总是与其他图像相比较。有人可以帮我解决吗?代码如下:

AVCaptureSession *session = [[AVCaptureSession alloc] init];

//Added by jigar
session.sessionPreset = AVCaptureSessionPreset640x480;
//[[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] supportsAvCaptureSessionPreset:AVCaptureSessionPreset640x480];

//End
// Create device input and add to current session
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
[session addInput:input];

// Create video output and add to current session
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];

// Start session configuration
[session beginConfiguration];
[device lockForConfiguration:nil];

// Set torch to on
if(flashMode == UIImagePickerControllerCameraFlashModeAuto)
{
    device.torchMode = AVCaptureTorchModeAuto;
}
else if(flashMode == UIImagePickerControllerCameraFlashModeOn){
    device.torchMode = AVCaptureTorchModeOn;
}
else if(flashMode == UIImagePickerControllerCameraFlashModeOff){
    device.torchMode = AVCaptureTorchModeOff;
}

[device unlockForConfiguration];
[session commitConfiguration];
//    [session startRunning];
[currentPicker takePicture];
//        [session stopRunning];
//        session = nil;

0 个答案:

没有答案