Example #1
0
            public void SetCameraZoom(double zoomFactor)
            {
                var error = new NSError();

                if (CaptureDevice != null && !CaptureDevice.RampingVideoZoom)
                {
                    CaptureDevice.LockForConfiguration(out error);
                    CaptureDevice.VideoZoomFactor = (nfloat)zoomFactor;
                    CaptureDevice.UnlockForConfiguration();
                }
            }
Example #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 camera operation
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    errorCamera("No Camera detected", "Seems your " + UIDevice.CurrentDevice.UserInterfaceIdiom + " has no camera. You must have a camera installed to use this feature");
                    CameraAvailable = false;
                    return;
                }

                else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    errorCamera("No Camera detected", "Seems your " + UIDevice.CurrentDevice.UserInterfaceIdiom + " has no camera. You must have a camera installed to use this feature");
                    CameraAvailable = false;
                    return;
                }
            }
            else
            {
                CaptureDevice.LockForConfiguration(out Error);
                if (Error != null)
                {
                    Console.WriteLine("Error detected in camera configuration: {0} ", Error.LocalizedDescription);
                    CaptureDevice.UnlockForConfiguration();
                    return;
                }
                else
                {
                    //configure a stream for 40 frames per second fps
                    CaptureDevice.ActiveVideoMinFrameDuration = new CMTime(1, 40);

                    //unlock configuration
                    CaptureDevice.UnlockForConfiguration();

                    //get input from capture device
                    Input = AVCaptureDeviceInput.FromDevice(CaptureDevice);

                    if (Input == null)
                    {
                        switch (UIDevice.CurrentDevice.UserInterfaceIdiom)
                        {
                        case UIUserInterfaceIdiom.Pad:
                            errorCamera("No Input", "No input detected from the camera on your: " + UIUserInterfaceIdiom.Pad);
                            CameraAvailable = false;
                            return;

                            break;

                        case UIUserInterfaceIdiom.Phone:
                            errorCamera("No Input", "No input detected from the camera on your: " + UIUserInterfaceIdiom.Phone);
                            CameraAvailable = false;
                            return;

                            break;
                        }
                    }

                    else
                    {
                        //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);

                        CameraAvailable = true;
                    }
                }
            }
        }
Example #3
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;
        }
Example #4
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // create a new window instance based on the screen size
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();

            // If you have defined a root view controller, set it here:
            initialViewController     = Storyboard.InstantiateInitialViewController() as UIViewController;
            Window.RootViewController = initialViewController;
            UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(14, 125, 202);
            UITabBar.Appearance.BackgroundColor        = UIColor.White;
            // make the window visible
            Window.MakeKeyAndVisible();

            // Create a new capture session
            Session = new AVCaptureSession();
            Session.SessionPreset = AVCaptureSession.PresetMedium;

            // Create a device input
            CaptureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
            if (CaptureDevice == null)
            {
                //throw new Exception("Video recording not supported on this device");
            }
            else
            {
                // Prepare device for configuration
                if (!CaptureDevice.LockForConfiguration(out Error))
                {
                    // There has been an issue, abort
                    Console.WriteLine("Error: {0}", Error.LocalizedDescription);
                    CaptureDevice.UnlockForConfiguration();
                    return(false);
                }

                // 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(false);
                }

                // 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;
            }
            return(true);
        }