Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

xamarin.ios - How To add OverlayView in Xamarin IOS Live Camera

  • I am accessing the live camera but i want to add an overlay above it, to take a specific picture and save the picture insde an overlay.
  • My goal is as shown on the picture below

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use UIImagePickerController to do that.

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

  • I'm sure you can get the grey effect with Alpha property of view.
  • you can make the line using UIBezierPath

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

Here is the rough example of that.

    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();

Update:

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.

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...