这似乎是一项简单的任务,但它快把我逼疯了。是否可以将包含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的安全问题。这是真的吗?
我只想说清楚:我不想为相机保存图像。我想保存叠加在另一个图像上的透明预览层,从而创建透明度。但由于某些原因,我无法使其工作。
https://stackoverflow.com/questions/9012397
复制相似问题