我有一个实时相机 View ,当我截取屏幕截图时,我只想将其中的一部分包含在圆形 UIImage 中。我得到的只是圆形 UIImage 和白色背景。 我将圆形图像称为circleImage,将相机 View 称为camView:
self.camView = self.faceImage.snapshotViewAfterScreenUpdates(false)
UIGraphicsBeginImageContextWithOptions(self.circleImage.bounds.size, false, 0);
self.circleImage.drawViewHierarchyInRect(self.camView.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
var imageData:NSData = UIImagePNGRepresentation(image)
UIGraphicsEndImageContext();
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
最佳答案
不幸的是,这是想要的行为,无法使用 renderInContext
或 drawViewHierarchy
捕获 AVCaptureVideoPreviewLayer 的内容,唯一的解决方案似乎是读取 session 的数据输出来自缓冲区委托(delegate),当您需要图像时,您可以从这里获取它。
欲了解更多信息,请查看here ,还有一个很好的替代解决方案。
关于ios - 截图时没有相机 View ,只有白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074195/