private void Initialize() { var captureSession = new MonoTouch.AVFoundation.AVCaptureSession(); previewLayer = new MonoTouch.AVFoundation.AVCaptureVideoPreviewLayer(captureSession) { LayerVideoGravity = MonoTouch.AVFoundation.AVLayerVideoGravity.ResizeAspectFill, Frame = this.Bounds }; var device = MonoTouch.AVFoundation.AVCaptureDevice.DefaultDeviceWithMediaType( MonoTouch.AVFoundation.AVMediaType.Video); if (device == null) { System.Diagnostics.Debug.WriteLine("No device detected."); return; } NSError error; var input = new MonoTouch.AVFoundation.AVCaptureDeviceInput(device, out error); captureSession.AddInput(input); this.Layer.AddSublayer(previewLayer); captureSession.StartRunning(); }
public override void ViewDidLoad() { CALayer _layer = new CALayer(); base.ViewDidLoad(); var captureSession = new MonoTouch.AVFoundation.AVCaptureSession(); var previewLayer = new MonoTouch.AVFoundation.AVCaptureVideoPreviewLayer(captureSession) { LayerVideoGravity = MonoTouch.AVFoundation.AVLayerVideoGravity.ResizeAspectFill, Frame = this.View.Bounds }; var device = MonoTouch.AVFoundation.AVCaptureDevice.DefaultDeviceWithMediaType( MonoTouch.AVFoundation.AVMediaType.Video); NSError error; var input = new MonoTouch.AVFoundation.AVCaptureDeviceInput(device, out error); captureSession.AddInput(input); this.View.Layer.AddSublayer(previewLayer); output = new AVCaptureStillImageOutput(); output.OutputSettings = NSDictionary.FromObjectAndKey(new NSString("AVVideoCodecKey"), new NSString("AVVideoCodecJPEG")); captureSession.AddOutput(output); var button = new UIButton(new RectangleF((this.View.Frame.Width - 50) / 2, this.View.Frame.Height - 60, 50, 50)); button.SetTitle("Click", UIControlState.Normal); button.TouchUpInside += HandleButtCaptureImageTouchUpInside; this.View.Add(button); _layer.Frame = this.View.Bounds; _layer.Delegate = new CustomLayerDelegate(); _layer.SetNeedsDisplay(); this.View.Layer.AddSublayer(_layer); captureSession.StartRunning(); // Perform any additional setup after loading the view, typically from a nib. }