如何一次在屏幕上显示多个相机预览?如果我启动一个新的 AVCaptureSession,另一个会停止。如果我用与另一个会话相同的会话初始化一个新的 AVCaptureVideoPreviewLayer,另一个 AVCaptureVideoPreviewLayer 将停止显示相机源。我怎样才能克服这个问题,并在屏幕上的两个不同位置显示相机馈送?
问问题
330 次
1 回答
0
// in this method get CameraView Buffer Image and set Preview view
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
@autoreleasepool
{
NSLog(@"Capturecall");
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
/*Lock the image buffer*/
CVPixelBufferLockBaseAddress(imageBuffer,0);
/*Get information about the image*/
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
/*Create a CGImageRef from the CVImageBufferRef*/
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef newImage = CGBitmapContextCreateImage(newContext);
/*We release some components*/
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
UIImage *image= [UIImage imageWithCGImage:newImage scale:1.0 orientation:UIImageOrientationRight];
CGImageRelease(newImage);
dispatch_async(dispatch_get_main_queue(),
^{
UIImage * blurredImage=[imagefilters GaussianBlurWithImage:image AndRadius:_brightnessValue];
[self.backgroundpreview setImage:blurredImage];
});
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}}
于 2019-02-06T10:45:44.853 回答