【发布时间】:2019-02-04 23:29:16
【问题描述】:
我有一个相机应用程序,它在 AVCaptureVideoPreviewLayer 实例中显示视频预览,其中包括一个 CGRect(例如用户周围的框架)。该层与包含该层的UIView 大小相同(例如 667x375)。
如何将CGRect 从图层的坐标空间转换到图像输出?
【问题讨论】:
标签: uikit calayer avcapturedevice avcaptureoutput
我有一个相机应用程序,它在 AVCaptureVideoPreviewLayer 实例中显示视频预览,其中包括一个 CGRect(例如用户周围的框架)。该层与包含该层的UIView 大小相同(例如 667x375)。
如何将CGRect 从图层的坐标空间转换到图像输出?
【问题讨论】:
标签: uikit calayer avcapturedevice avcaptureoutput
我自己找到了答案;正确的方法是使用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)
其中image 是UIImage 实例。
【讨论】: