- 我正在访问实时摄像头,但我想在其上方添加一个叠加层,以拍摄特定照片并将图片保存在叠加层中。
- 我的目标如下图所示
问问题
1728 次
2 回答
2
你可以使用UIImagePickerController来做到这一点。
首先制作一个覆盖视图,就像您的问题中显示的那样。
- 我相信您可以使用视图的Alpha属性获得灰色效果。
- 您可以使用UIBezierPath制作线条
完成覆盖视图后,将其分配给UIImagePickerController的CameraOverlayView属性
这是一个粗略的例子。
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
类获取图像的裁剪版本。传递相机叠加层的矩形和相机拍摄的图片的图像参考,该类将返回相机叠加层覆盖的裁剪图像。
这是来自 Objective C 的示例,我相信您可以在 Xamarin.iOS 中执行类似的操作
CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
// or use the UIImage wherever you like
[UIImageView setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
于 2019-05-17T09:25:49.063 回答
1
我设法添加了 CameraOverlayView,“以允许用户在给定的矩形内拍照”
private UIImagePickerController _imagePicker;
private void OpenCameraAndTakePhoto() {
_imagePicker = new UIImagePickerController();
_imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
_imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.Camera);
_imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
_imagePicker.Canceled += Handle_Canceled;
_imagePicker.ShowsCameraControls = true;
UIView view = new UIView(new CGRect(30, 200, 250, 120));
view.Layer.BorderColor = UIColor.Blue.CGColor;
view.Layer.BorderWidth = 3.0f;
_imagePicker.CameraOverlayView = view;
PresentModalViewController(_imagePicker, true);
}
于 2019-05-17T13:38:00.300 回答