0
我真的不知道這裏發生了什麼...相機預覽圖層似乎凍結,CaptureStill ...塊永遠不會被執行。但是,如果我在執行應用程序的開始時將閃光燈關閉,則可以很好地拍攝照片。還應該注意的是,我碰到這個線程:Toggling Flash on AVCaptureDevice requires Stopping and Starting AVCaptureSEssion,並決定繼續嘗試停止會話並重新啓動它,它似乎工作。沒有更多的凍結,但關閉會話並重新開啓後,攝像機會稍微凍結,這是不可接受的。思考?AVCaptureSession與閃光燈凍結在
- (void)cameraButtonPressed{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[device lockForConfiguration:nil];
if ([defaults objectForKey:@"Flash"])
{
SPFlashButton option = [[defaults objectForKey:@"Flash"] intValue];
if (option == SPFlashButtonTypeOff)
{
[device setFlashMode:AVCaptureFlashModeOff];
}
else if (option == SPFlashButtonTypeOn)
{
[device setFlashMode:AVCaptureFlashModeOn];
}
else if (option == SPFlashButtonTypeAuto)
{
[device setFlashMode:AVCaptureFlashModeAuto];
}
}
else
{
[device setFlashMode:AVCaptureFlashModeAuto];
}
[device unlockForConfiguration];
AVCaptureConnection *stillImageConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
stillImageConnection = connection;
break;
}
}
if (stillImageConnection) { break; }
}
UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation avcaptureOrientation = [self avOrientationForDeviceOrientation:curDeviceOrientation];
[stillImageConnection setVideoOrientation:avcaptureOrientation];
[stillImageConnection setVideoScaleAndCropFactor:self.zoomScale];
[stillImageOutput setOutputSettings:[NSDictionary dictionaryWithObject:AVVideoCodecJPEG
forKey:AVVideoCodecKey]];
[stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [UIImage imageWithData:jpegData];
//do stuff with the image
}];
}