gpt4 book ai didi

ios - 如何在 AVCaptureVideoPreviewLayer 上显示覆盖

转载 作者:可可西里 更新时间:2023-11-01 04:44:15 26 4
gpt4 key购买 nike

我需要在 AVCaptureVideoPreviewLayer 上显示图像(帧)叠加层。我该怎么做?

-(void) viewDidAppear:(BOOL)animated
{
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
[session commitConfiguration];

CALayer *viewLayer = self.vImagePreview.layer;
NSLog(@"viewLayer = %@", viewLayer);

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];

_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];

[session addOutput:_stillImageOutput];

[session startRunning];

}

在视频输出层上添加新 View 不起作用。预览层显示在所有 View 之上。

我的 View 层次结构:

  • 主视图
    • 叠加 View
    • 视频输出 View

My frame appears under the video output view

最佳答案

虽然这个问题是 N 年前提出的,但我还是想分享我的确切答案。几分钟后,我能够理解古杰明的话。事实上,解决方案可以通过编程方式完成。但如果您在 XIB 或 Storyboard 中进行操作,请检查这种层次结构。不要将任何 subview 放入您的 CameraPreviewView(其图层将成为相机的 uiview)。

enter image description here

关于ios - 如何在 AVCaptureVideoPreviewLayer 上显示覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17965635/

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