使用此方法从AVCaptureSession
where stillImageOutput
is捕获静止图像AVCaptureStillImageOutput
:
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CVImageBufferRef imageBuffer =CMSampleBufferGetImageBuffer(imageSampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer];
CIContext *temporaryContext = [CIContext contextWithOptions:nil];
CGImageRef videoImage =[temporaryContext
createCGImage:ciImage
fromRect:CGRectMake(
0, 0,
CVPixelBufferGetWidth(imageBuffer),
CVPixelBufferGetHeight(imageBuffer)
)];
UIImage *image = [[UIImage alloc] initWithCGImage:videoImage];
self.imageView.image = image;
}