gpt4 book ai didi

iPhone 4 相机不透明度

转载 作者:行者123 更新时间:2023-12-03 21:19:34 28 4
gpt4 key购买 nike

我想知道是否可以设置相机输入的不透明度?例如,如果我在相机下面有图层,我想通过相机图层显示..

我像这样使用相机:

- (void)addVideoPreviewLayer {
[self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]] autorelease]];
[[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

}

- (void)addVideoInput {
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([[self captureSession] canAddInput:videoIn])
[[self captureSession] addInput:videoIn];
else
NSLog(@"Couldn't add video input");
}
else
NSLog(@"Couldn't create video input");
}
else
NSLog(@"Couldn't create video capture device");
}

并通过以下方式启动它:

[self setCaptureManager:[[CaptureSessionManager alloc] init]];
[[self captureManager] addVideoInput];
[[self captureManager] addVideoPreviewLayer];
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:layerRect];
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];

有可能吗?如果是的话,该怎么做?

最佳答案

previewLayer 不像普通的 CALayer 那样合成,因此更改其不透明度不起作用也就不足为奇了。

您可以尝试做的是使用此代码(http://developer.apple.com/library/ios/#qa/qa1702/_index.html)实时捕获来自相机的输入,转换它到 UIImage,并将该图像粘贴到 UIImageView 中。我发现,使用 AVCaptureSessionPresetMedium 的 session 设置,您应该能够以 20-30 fps 的速度更新 UIImageView,这可能足以满足您想要完成的任务。

关于iPhone 4 相机不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6115832/

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