0

I have a camera app which shows a video preview in a AVCaptureVideoPreviewLayer instance, which includes a CGRect (for example a frame around the user). This layer has the same size as the UIView which contains the layer (for instance 667x375).

How do I translate the CGRect from the layer's coordinate space to the image output?

1 Answer 1

0

I found the answer myself; the right way is to use the method 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)

Where image is a UIImage instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.