gpt4 book ai didi

avfoundation - 多个 AVCaptureVideoPreviewLayers

转载 作者:行者123 更新时间:2023-12-05 01:37:07 30 4
gpt4 key购买 nike

如何一次在屏幕上显示多个相机预览?
如果我开始一个新的 AVCaptureSession,另一个就会停止。如果我使用与另一个 session 相同的 session 初始化一个新的 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);
}}

关于avfoundation - 多个 AVCaptureVideoPreviewLayers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11513704/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com