示例#1
0
        public override void FinishedLaunching(UIApplication application)
        {
            // Create a new capture session
            Session = new AVCaptureSession();
            Session.SessionPreset = AVCaptureSession.PresetMedium;

            // Create a device input
            CaptureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
            if (CaptureDevice == null)
            {
                // Video capture not supported, abort
                Console.WriteLine("Video recording not supported on this device");
                CameraAvailable = false;
                return;
            }

            // Prepare device for configuration
            CaptureDevice.LockForConfiguration(out Error);
            if (Error != null)
            {
                // There has been an issue, abort
                Console.WriteLine("Error: {0}", Error.LocalizedDescription);
                CaptureDevice.UnlockForConfiguration();
                return;
            }

            // Configure stream for 15 frames per second (fps)
            CaptureDevice.ActiveVideoMinFrameDuration = new CMTime(1, 15);

            // Unlock configuration
            CaptureDevice.UnlockForConfiguration();

            // Get input from capture device
            Input = AVCaptureDeviceInput.FromDevice(CaptureDevice);
            if (Input == null)
            {
                // Error, report and abort
                Console.WriteLine("Unable to gain input from capture device.");
                CameraAvailable = false;
                return;
            }

            // Attach input to session
            Session.AddInput(Input);

            // Create a new output
            var output   = new AVCaptureVideoDataOutput();
            var settings = new AVVideoSettingsUncompressed();

            settings.PixelFormatType = CVPixelFormatType.CV32BGRA;
            output.WeakVideoSettings = settings.Dictionary;

            // Configure and attach to the output to the session
            Queue    = new DispatchQueue("ManCamQueue");
            Recorder = new OutputRecorder();
            output.SetSampleBufferDelegate(Recorder, Queue);
            Session.AddOutput(output);

            // Configure and attach a still image output for bracketed capture
            StillImageOutput = new AVCaptureStillImageOutput();
            var dict = new NSMutableDictionary();

            dict[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG);
            Session.AddOutput(StillImageOutput);

            // Let tabs know that a camera is available
            CameraAvailable = true;
        }
示例#2
0
		public override void FinishedLaunching (UIApplication application)
		{
			// Create a new capture session
			Session = new AVCaptureSession ();
			Session.SessionPreset = AVCaptureSession.PresetMedium;

			// Create a device input
			CaptureDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);
			if (CaptureDevice == null) {
				// Video capture not supported, abort
				Console.WriteLine ("Video recording not supported on this device");
				CameraAvailable = false;
				return;
			}

			// Prepare device for configuration
			CaptureDevice.LockForConfiguration (out Error);
			if (Error != null) {
				// There has been an issue, abort
				Console.WriteLine ("Error: {0}", Error.LocalizedDescription);
				CaptureDevice.UnlockForConfiguration ();
				return;
			}

			// Configure stream for 15 frames per second (fps)
			CaptureDevice.ActiveVideoMinFrameDuration = new CMTime (1, 15);

			// Unlock configuration
			CaptureDevice.UnlockForConfiguration ();

			// Get input from capture device
			Input = AVCaptureDeviceInput.FromDevice (CaptureDevice);
			if (Input == null) {
				// Error, report and abort
				Console.WriteLine ("Unable to gain input from capture device.");
				CameraAvailable = false;
				return;
			}

			// Attach input to session
			Session.AddInput (Input);

			// Create a new output
			var output = new AVCaptureVideoDataOutput ();
			var settings = new AVVideoSettingsUncompressed ();
			settings.PixelFormatType = CVPixelFormatType.CV32BGRA;
			output.WeakVideoSettings = settings.Dictionary;

			// Configure and attach to the output to the session
			Queue = new DispatchQueue ("ManCamQueue");
			Recorder = new OutputRecorder ();
			output.SetSampleBufferDelegate (Recorder, Queue);
			Session.AddOutput (output);

			// Configure and attach a still image output for bracketed capture
			StillImageOutput = new AVCaptureStillImageOutput ();
			var dict = new NSMutableDictionary();
			dict[AVVideo.CodecKey] = new NSNumber((int) AVVideoCodec.JPEG);
			Session.AddOutput (StillImageOutput);

			// Let tabs know that a camera is available
			CameraAvailable = true;
		}