gpt4 book ai didi

ios - AVFoundation 相机不可见

转载 作者:行者123 更新时间:2023-11-29 01:34:29 25 4
gpt4 key购买 nike

我刚刚启动 AVFoundation,我正在 try catch 图像。问题是我能够捕获图像,但无法在我的 View 中看到相机。这是我的代码:

     session = [AVCaptureSession new];
if([session canSetSessionPreset:AVCaptureSessionPresetHigh])
[session setSessionPreset:AVCaptureSessionPresetHigh];//specifies photo quality

AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
[session addInput:deviceInput];

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view]layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:_cameraView.frame];
[rootLayer insertSublayer:previewLayer atIndex:0];

stillImageOutput = [AVCaptureStillImageOutput new];
[stillImageOutput setOutputSettings:[[NSDictionary alloc]initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
[session addOutput:stillImageOutput];
[session startRunning];

我的代码有什么问题吗?

最佳答案

试试 [[rootLayer layer] addSublayer:previewLayer];

对我来说很管用!

关于ios - AVFoundation 相机不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124726/

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