ios - 截图时没有相机 View ,只有白色背景

标签 ios swift camera uiimage

我有一个实时相机 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)

最佳答案

不幸的是,这是想要的行为,无法使用 renderInContextdrawViewHierarchy 捕获 AVCaptureVideoPreviewLayer 的内容,唯一的解决方案似乎是读取 session 的数据输出来自缓冲区委托(delegate),当您需要图像时,您可以从这里获取它。
欲了解更多信息,请查看here ,还有一个很好的替代解决方案。

关于ios - 截图时没有相机 View ,只有白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074195/

相关文章:

iphone - 核心数据,一对多关系

ios - UITapGestureRecognizer 不适用于特定的 [UIView] 数组

swift - 获取2个数组中公共(public)元素列表的性能

android - 截取 SurfaceView 的屏幕截图

0x00000040 处的 Android 致命信号 11 (SIGSEGV)(代码=1)错误

iOS 无损图像编辑

ios - 获取主队列 block 未在主线程上执行

iphone - 我可以使用UIBezierPath在UITableView部分周围绘制阴影图像吗?

ios - 在 `UIImageView` (Swift) 中加载网站预览

video - Flutter 直播