【问题标题】:Translate CGRect from CALayer to UIImage将 CGRect 从 CALayer 转换为 UIImage
【发布时间】:2019-02-04 23:29:16
【问题描述】:

我有一个相机应用程序,它在 AVCaptureVideoPreviewLayer 实例中显示视频预览,其中包括一个 CGRect(例如用户周围的框架)。该层与包含该层的UIView 大小相同(例如 667x375)。

如何将CGRect 从图层的坐标空间转换到图像输出?

【问题讨论】:

    标签: uikit calayer avcapturedevice avcaptureoutput


    【解决方案1】:

    我自己找到了答案;正确的方法是使用metadataOutputRectConverted的方法。

            let tempRect = layer.metadataOutputRectConverted(fromLayerRect: rect)
            let trans_rect = CGRect(x: tempRect.origin.x * image.size.width,
                                    y: tempRect.origin.y * image.size.height,
                                    width: tempRect.width * image.size.width,
                                    height: tempRect.height * image.size.height)
    

    其中imageUIImage 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 2023-03-16
      • 2013-09-01
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多