Ejemplo n.º 1
0
        /// <summary>
        /// Initialize camera
        /// </summary>
        /// <param name="onImage">Callback <see cref="Action{T}"/> with <see cref="UIImage"/>,
        /// triggered when picture is taken</param>
        public void Initialize(Action <UIImage> onImage)
        {
            if (_initialized)
            {
                return;
            }

            _onImage = onImage;

            var shutterImage = Configuration.ShutterImage ??
                               UIImage.FromBundle("ic_radio_button_checked");

            if (Configuration.TintIcons)
            {
                ShutterButton.TintColor = Configuration.TintColor;
                shutterImage            =
                    shutterImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            }

            ShutterButton.SetImage(shutterImage, UIControlState.Normal);

            Initialize();

            _willEnterForegroundObserver =
                UIApplication.Notifications.ObserveWillEnterForeground(WillEnterForeground);

            _initialized = true;
        }
        void ReleaseDesignerOutlets()
        {
            if (CameraFeedView != null)
            {
                CameraFeedView.Dispose();
                CameraFeedView = null;
            }

            if (OverlayImageView != null)
            {
                OverlayImageView.Dispose();
                OverlayImageView = null;
            }

            if (ShutterButton != null)
            {
                ShutterButton.Dispose();
                ShutterButton = null;
            }

            if (SwapCameraButton != null)
            {
                SwapCameraButton.Dispose();
                SwapCameraButton = null;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize video view
        /// </summary>
        /// <param name="onVideoFinished">Callback <see cref="Action{T}"/> with <see cref="NSUrl"/>
        /// with the url of the video when recording is done</param>
        /// <param name="startCamera">Optional: <see cref="bool"/> describing whether to start the camera immediately.
        /// Defaults to <c>true</c></param>
        public void Initialize(Action <NSUrl> onVideoFinished, bool startCamera = true)
        {
            if (_initialized)
            {
                return;
            }

            _onVideoFinished = onVideoFinished;

            _videoStartImage = Configuration.VideoStartImage ?? UIImage.FromBundle("video_button");
            _videoStopImage  = Configuration.VideoStopImage ?? UIImage.FromBundle("video_button_rec");

            if (Configuration.TintIcons)
            {
                ShutterButton.TintColor = Configuration.TintColor;

                _videoStartImage = _videoStartImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                _videoStopImage  = _videoStopImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            }

            ShutterButton.SetImage(_videoStartImage, UIControlState.Normal);

            Initialize();

            // Start camera when views enters foreground
            _willEnterForegroundObserver = UIApplication.Notifications.ObserveWillEnterForeground(WillEnterForeground);

            _initialized = true;
        }
Ejemplo n.º 4
0
        private void ToggleRecording()
        {
            if (_videoOutput == null)
            {
                return;
            }

            _isRecording = !_isRecording;

            var shotImage = _isRecording ? _videoStopImage : _videoStartImage;

            ShutterButton.SetImage(shotImage, UIControlState.Normal);

            if (_isRecording)
            {
                var outputPath = Path.Combine(Path.GetTempPath(), "output.mov");
                var outputUrl  = NSUrl.FromString("file:///" + outputPath);

                var fileManager = NSFileManager.DefaultManager;
                if (fileManager.FileExists(outputPath))
                {
                    NSError error;
                    fileManager.Remove(outputPath, out error);
                    if (error != null)
                    {
                        Console.WriteLine($"Error removing item at path {outputPath}");
                        _isRecording = false;
                        return;
                    }
                }

                FlipButton.Enabled  = false;
                FlashButton.Enabled = false;
                var connection = _videoOutput.ConnectionFromMediaType(AVMediaType.Video);
                if (connection.SupportsVideoOrientation)
                {
                    connection.VideoOrientation = GetOrientation();
                }
                _videoOutput.StartRecordingToOutputFile(outputUrl, this);
            }
            else
            {
                _videoOutput.StopRecording();
                FlipButton.Enabled  = true;
                FlashButton.Enabled = true;
            }
        }
Ejemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.BusinessCardsLayout);

            cameraView = FindViewById <ScanbotCameraView>(Resource.Id.camera);

            pictureCallbackDelegate = new PictureCallbackDelegate();
            pictureCallbackDelegate.OnPictureTakenHandler += ProcessTakenPicture;
            cameraView.AddPictureCallback(pictureCallbackDelegate);

            cameraView.SetCameraOpenCallback(this);
            cameraView.SetAutoFocusSound(false);

            progress = FindViewById <ProgressBar>(Resource.Id.progressView);

            shutterButton        = FindViewById <ShutterButton>(Resource.Id.snap);
            shutterButton.Click += delegate
            {
                cameraView.TakePicture(false);
            };
            shutterButton.Post(delegate
            {
                shutterButton.ShowAutoButton();
            });

            sdk = new IO.Scanbot.Sdk.ScanbotSDK(this);
            var detector = sdk.MultipleObjectsDetector();

            if (modParams != null)
            {
                detector.SetParams(modParams);
            }

            var handler = MultipleObjectsFrameHandler.Attach(cameraView, detector);

            var polygon = FindViewById <MultiplePolygonsView>(Resource.Id.polygonView);

            handler.AddResultHandler(new MultipleObjectsCallback());

            FindViewById(Resource.Id.flash).Click += delegate
            {
                flashEnabled = !flashEnabled;
                cameraView.UseFlash(flashEnabled);
            };
        }
Ejemplo n.º 6
0
        void ReleaseDesignerOutlets()
        {
            if (EnableLivePhotoButton != null)
            {
                EnableLivePhotoButton.Dispose();
                EnableLivePhotoButton = null;
            }

            if (LiveIndicator != null)
            {
                LiveIndicator.Dispose();
                LiveIndicator = null;
            }

            if (SnapButton != null)
            {
                SnapButton.Dispose();
                SnapButton = null;
            }
        }
 public Task SC_PressShutterButton(ShutterButton state);
        protected override void OnCreate(Bundle savedInstanceState)
        {
            SupportRequestWindowFeature(WindowCompat.FeatureActionBarOverlay);
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CameraViewDemo);

            SupportActionBar.Hide();

            cameraView = FindViewById <ScanbotCameraView>(Resource.Id.scanbotCameraView);

            // In this example we demonstrate how to lock the orientation of the UI (Activity)
            // as well as the orientation of the taken picture to portrait.
            cameraView.LockToPortrait(true);

            // Uncomment to disable AutoFocus by manually touching the camera view:
            //cameraView.SetAutoFocusOnTouch(false);

            // Preview Mode: See https://github.com/doo/Scanbot-SDK-Examples/wiki/Using-ScanbotCameraView#preview-mode
            //cameraView.SetPreviewMode(CameraPreviewMode.FitIn);

            userGuidanceTextView = FindViewById <TextView>(Resource.Id.userGuidanceTextView);

            imageProcessingProgress = FindViewById <ProgressBar>(Resource.Id.imageProcessingProgress);

            contourDetectorFrameHandler = ContourDetectorFrameHandler.Attach(cameraView);
            polygonView = FindViewById <PolygonView>(Resource.Id.scanbotPolygonView);
            polygonView.SetStrokeColor(Color.Red);
            polygonView.SetStrokeColorOK(Color.Green);
            contourDetectorFrameHandler.AddResultHandler(polygonView);
            contourDetectorFrameHandler.AddResultHandler(this);

            // See https://github.com/doo/Scanbot-SDK-Examples/wiki/Detecting-and-drawing-contours#contour-detection-parameters
            contourDetectorFrameHandler.SetAcceptedAngleScore(60);
            contourDetectorFrameHandler.SetAcceptedSizeScore(70);

            autoSnappingController = AutoSnappingController.Attach(cameraView, contourDetectorFrameHandler);
            autoSnappingController.SetIgnoreBadAspectRatio(ignoreBadAspectRatio);

            cameraView.AddPictureCallback(this);
            cameraView.SetCameraOpenCallback(this);

            shutterButton        = FindViewById <ShutterButton>(Resource.Id.shutterButton);
            shutterButton.Click += delegate
            {
                cameraView.TakePicture(false);
            };
            shutterButton.Visibility = ViewStates.Visible;

            FindViewById(Resource.Id.scanbotFlashButton).Click += delegate
            {
                cameraView.UseFlash(!flashEnabled);
                flashEnabled = !flashEnabled;
            };

            autoSnappingToggleButton        = FindViewById <Button>(Resource.Id.autoSnappingToggleButton);
            autoSnappingToggleButton.Click += delegate
            {
                autoSnappingEnabled = !autoSnappingEnabled;
                SetAutoSnapEnabled(autoSnappingEnabled);
            };

            shutterButton.Post(() =>
            {
                SetAutoSnapEnabled(autoSnappingEnabled);
            });
        }