【问题标题】:No camera view just white background when taking a screeshot截屏时没有相机视图,只有白色背景
【发布时间】:2015-06-26 13:16:26
【问题描述】:

我有一个实时摄像头视图,我希望在截屏时只将其中的一部分包含在圆形 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)

【问题讨论】:

    标签: ios swift camera uiimage


    【解决方案1】:

    不幸的是,这是想要的行为,没有办法使用renderInContextdrawViewHierarchy 捕获 AVCaptureVideoPreviewLayer 的内容,唯一的解决方案似乎是在您需要图像时从缓冲区委托读取会话的数据输出你从这里抓住它。
    更多信息请查看here,还有一个很好的替代解决方案。

    【讨论】:

    • 谢谢安德里亚!我会研究一下,希望它对我有用。
    猜你喜欢
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多