【发布时间】:2012-02-19 05:00:33
【问题描述】:
这似乎是一个简单的任务,但它让我发疯。 是否可以将包含 AVCaptureVideoPreviewLayer 作为子图层的 UIView 转换为要保存的图像? 我想创建一个增强现实叠加层并有一个按钮将图片保存到相机胶卷。按住电源按钮 + 主页键将屏幕截图捕获到相机胶卷,这意味着我所有的捕获逻辑都在工作,并且任务是可能的。但我似乎无法使其以编程方式工作。
我正在使用 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 的安全问题。这是真的吗?
明确一点:我不想为相机保存图像。我想保存叠加在另一个图像上的透明预览层,从而创建透明度。但由于某种原因,我无法使其工作。
【问题讨论】:
标签: iphone objective-c uiview avfoundation