在相机iOS上绘制叠加层 [英] Draw overlay on camera iOS

查看:178
本文介绍了在相机iOS上绘制叠加层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户需要能够拍摄其ID的照片.我需要在相机视图中添加一个蓝框作为指导.指南在所有设备尺寸上都应具有相同的长宽比,并在标签上贴上说明.我可以使用UIImagePicker完成此操作吗?

Users need to be able to take photo of their ID. I need to add a blue frame to camera view as a guide. Guide should have same aspect ratio on all device sizes and fit a label with instructions. Can I accomplish this using UIImagePicker?

这是一些不完整的代码.谢谢你的帮助.

Here is some incomplete code. Thanks for any help.

UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
CGRect overlayRect = CGRectMake(0, 0, self.view.frame.size.height - 16, self.view.frame.size.width - 16);
[overlayImage setFrame:overlayRect];
[self.imagePicker setCameraOverlayView:overlayImage];

推荐答案

使用AVCaptureDeviceAVCaptureSessionAVCaptureVideoPreviewLayerAVCapturePhotoOutput.

AVCaptureDeviceInput设置为捕获会话的输入,并将照片输出作为捕获会话的输出.用AVCaptureSession初始化AVCaptureVideoPreviewLayer并添加到view.layer想法addSublayer中.您可以从情节提要或以编程方式实例化的控制器中使用UIViewController,添加覆盖图或有角的view.layer.borderWidthUIBezierPath的图片.将控制器设置为AVCapturePhotoCaptureDelegate,添加委托方法.使用capturePhoto(with:delegate:)方法.享受.

Set AVCaptureDeviceInput as input of capture session, and photo output as output of capture session. Initialize AVCaptureVideoPreviewLayer with AVCaptureSession and add to your view.layer thought addSublayer. You can use UIViewController from storyboard or programmatically instantiated controller, add picture of overlay or cornered view.layer.borderWidth or UIBezierPath. Set up controller as AVCapturePhotoCaptureDelegate, add delegate methods. Use capturePhoto(with:delegate:) method. Enjoy.

这篇关于在相机iOS上绘制叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆