如何在 Xamarin IOS Live Camera 中添加 OverlayView [英] How To add OverlayView in Xamarin IOS Live Camera

查看:18
本文介绍了如何在 Xamarin IOS Live Camera 中添加 OverlayView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我正在访问实时摄像头,但我想在其上方添加一个叠加层,以拍摄特定照片并将图片保存在叠加层中.
  • 我的目标如下图所示

推荐答案

您可以使用 UIImagePickerController 来做到这一点.

You can use UIImagePickerController to do that.

首先制作一个像您的问题中显示的那样的叠加视图.

First make a overlay view like the one shown in your question.

  • 我相信您可以通过视图的 Alpha 属性获得灰色效果.
  • 你可以使用 UIBezierPath
  • I'm sure you can get the grey effect with Alpha property of view.
  • you can make the line using UIBezierPath

当您完成叠加视图后,将其分配给 UIImagePickerController

when you are done with the overlay view then assign it to CameraOverlayView property of UIImagePickerController

这是一个粗略的例子.

    imagePicker = new UIImagePickerController();

    // set our source to the camera
    imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;

    // set
    imagePicker.MediaTypes = new string[] { "public.image" };

    // show the camera controls
    imagePicker.ShowsCameraControls = true;

    // This is where you assign the view that you want to overlay   
    imagePicker.CameraOverlayView = new CameraOverlayView();

<小时>

更新:

使用CGImageCreateWithImageInRect 类来获取图像的裁剪版本.传递相机覆盖的矩形和相机拍摄的图片的图像参考,该类将返回相机覆盖覆盖的裁剪图像.

Use CGImageCreateWithImageInRect class to get the cropped version of image. Pass camera overlay's rect and image reference of picture taken by camera and this class will return the cropped image that camera overlay covers.

这是一个来自 Objective C 的例子,我相信你可以在 Xamarin.iOS 中做类似的事情

Here is an example from Objective C and I'm sure you can do something similar in Xamarin.iOS

CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
// or use the UIImage wherever you like
[UIImageView setImage:[UIImage imageWithCGImage:imageRef]]; 
CGImageRelease(imageRef);

这篇关于如何在 Xamarin IOS Live Camera 中添加 OverlayView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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