我有一个实时相机视图,当我拍摄屏幕截图时,我只希望它的一部分包含在圆形UIImage中。我得到的只是一个圆形UIImage和一个白色背景。我称圆形图像为circleImage,相机视图为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)发布于 2015-06-26 21:55:28
不幸的是,这是想要的行为,没有办法使用renderInContext或drawViewHierarchy来捕获AVCaptureVideoPreviewLayer的内容唯一的解决方案似乎是从buffer委托读取会话的数据输出,当您需要从此处获取图像时。
有关更多信息,请查看here,还有一个很好的替代解决方案。
https://stackoverflow.com/questions/31074195
复制相似问题