首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >可以在图形环境中呈现AVCaptureVideoPreviewLayer吗?

可以在图形环境中呈现AVCaptureVideoPreviewLayer吗?
EN

Stack Overflow用户
提问于 2012-01-26 08:19:17
回答 2查看 5.3K关注 0票数 19

这似乎是一项简单的任务,但它快把我逼疯了。是否可以将包含AVCaptureVideoPreviewLayer作为子层的UIView转换为要保存的图像?我想创建增强现实覆盖图,并使用按钮将图片保存到相机胶卷中。按住电源按钮+Home键可以将屏幕截图捕捉到相机胶卷上,这意味着我的所有捕捉逻辑都在工作,并且任务是可能的。但我似乎不能让它以编程方式工作。

我正在使用AVCaptureVideoPreviewLayer捕捉摄像机图像的实时预览。我所有渲染图像的尝试都失败了:

  previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
//start the session, etc...


//this saves a white screen
- (IBAction)saveOverlay:(id)sender {
    NSLog(@"saveOverlay");

    UIGraphicsBeginImageContext(appDelegate.window.bounds.size);
        UIGraphicsBeginImageContext(scrollView.frame.size);

    [previewLayer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];


//    [appDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenshot, self, 
                                   @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

//这将渲染除预览层之外的所有内容,预览层为空。

[appDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];

我在某处读到这可能是由于iPhone的安全问题。这是真的吗?

我只想说清楚:我不想为相机保存图像。我想保存叠加在另一个图像上的透明预览层,从而创建透明度。但由于某些原因,我无法使其工作。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9012397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档