开发者

iPhone 4 camera opacity

I was wondering if it is possible to set the opacity of the camera input? For example if I have layers underneath the camera I want to be shown through the camera layer..

I work with the camera like this:

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

}

- (void)addVideoInput {
    AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVid开发者_如何学JAVAeo];   
    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");
}

And fire it up by:

[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]];

It is possible? And if yes, how can it be done?


The previewLayer isn't composited like ordinary CALayers, so it's not surprising that changing its opacity doesn't work.

What you can try to do is use this code (http://developer.apple.com/library/ios/#qa/qa1702/_index.html) to capture the input from the camera in real-time, convert it to a UIImage, and stick that image into a UIImageView. I've found that with a session setting of AVCaptureSessionPresetMedium, you should be able to update your UIImageView at 20-30 fps, which may be sufficient for what you are trying to accomplish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜