多AVCaptureVideoPreviewLayers

问题描述 投票:3回答:1

我怎样才能显示摄像机的多个预览屏幕上一次?如果我开始一个新的AVCaptureSession,其他人阻止。如果我初始化一个新AVCaptureVideoPreviewLayer使用相同的会话一个又一个,另一个AVCaptureVideoPreviewLayer停止显示相机饲料。我怎样才能克服这一点,并在屏幕上的两个不同的地方显示相机的饲料?

avfoundation avcapturesession
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);
}}
© www.soinside.com 2019 - 2024. All rights reserved.