多AVCaptureVideoPreviewLayers
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多AVCaptureVideoPreviewLayers相关的知识,希望对你有一定的参考价值。
我怎样才能显示摄像机的多个预览屏幕上一次?如果我开始一个新的AVCaptureSession,其他人阻止。如果我初始化一个新AVCaptureVideoPreviewLayer使用相同的会话一个又一个,另一个AVCaptureVideoPreviewLayer停止显示相机饲料。我怎样才能克服这一点,并在屏幕上的两个不同的地方显示相机的饲料?
答案
// 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);
以上是关于多AVCaptureVideoPreviewLayers的主要内容,如果未能解决你的问题,请参考以下文章