我想知道是否可以设置相机输入的不透明度?例如,如果我在相机下面有图层,我想通过相机层显示..
我像这样使用相机:
- (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]];
有可能吗?如果是的话,怎么办呢?
答案 0 :(得分:1)
previewLayer不像普通的CALayers那样合成,所以改变它的不透明度并不起作用也就不足为奇了。
您可以尝试做的是使用此代码(http://developer.apple.com/library/ios/#qa/qa1702/_index.html)实时捕获来自相机的输入,转换它是一个UIImage,并将该图像粘贴到UIImageView中。我发现使用AVCaptureSessionPresetMedium的会话设置,您应该能够以20-30 fps更新UIImageView,这可能足以满足您的目标。