Esempio n. 1
0
        void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            flashOn = !flashOn;
            if (flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = global::Android.Hardware.Camera.Open((int)cameraType);
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(surfaceTexture);
                    PrepareAndStartCamera();
                }
            }
            else
            {
                toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                camera.StopPreview();
                camera.Release();

                camera = global::Android.Hardware.Camera.Open((int)cameraType);
                var parameters = camera.GetParameters();
                parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Esempio n. 2
0
        public void OpenCamera(global::Android.Hardware.Camera camera)
        {
            _camera = camera;
            var cameraParams = _camera.GetParameters();

            if (Resources.Configuration.Orientation != global::Android.Content.Res.Orientation.Landscape)
            {
                cameraParams.Set("orientation", "portrait");
                _camera.SetDisplayOrientation(90);
                cameraParams.SetRotation(90);
            }
            else
            {
                cameraParams.Set("orientation", "landscape");
                _camera.SetDisplayOrientation(0);
                cameraParams.SetRotation(0);
            }

            var bestPictureSize = GetWorstPictureSize(cameraParams);

            if (bestPictureSize != default(Size))
            {
                cameraParams.SetPictureSize(bestPictureSize.Width, bestPictureSize.Height);
            }

            _camera.SetParameters(cameraParams);

            if (_shouldInitializeCamera)
            {
                _camera.SetPreviewDisplay(Holder);
                _camera.StartPreview();
                _shouldInitializeCamera = false;
            }
        }
Esempio n. 3
0
        void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            flashOn = !flashOn;
            if (flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = global::Android.Hardware.Camera.Open((int)cameraType);
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(surfaceTexture);

                    PrepareAndStartCamera();
                }
            }
            else
            {
                toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                camera.StopPreview();
                camera.Release();

                camera = global::Android.Hardware.Camera.Open((int)cameraType);


                var infoFocusCalibration      = global::Android.Hardware.Camera2.CameraCharacteristics.LensInfoFocusDistanceCalibration;
                var infoSupportHardLevel      = global::Android.Hardware.Camera2.CameraCharacteristics.InfoSupportedHardwareLevel;
                var infoMinimumFocus          = global::Android.Hardware.Camera2.CameraCharacteristics.LensPoseRotation;
                var infoSensorActiveArraySize = global::Android.Hardware.Camera2.CameraCharacteristics.SensorInfoActiveArraySize;

                //var paramters2 = camera2.

                var parameters = camera.GetParameters();

                parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                parameters.FocusMode = global::Android.Hardware.Camera.Parameters.FocusModeAuto;

                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                camera.SetDisplayOrientation(100);
                var max = camera.GetParameters().MaxNumFocusAreas;

                PrepareAndStartCamera();
                camera.StartFaceDetection();
            }
        }
Esempio n. 4
0
		private void ToggleFlashButtonTapped(object sender, EventArgs e)
		{
			_flashOn = !_flashOn;
			if (_flashOn)
			{
				if (cameraType == CameraFacing.Back)
				{
					toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
					cameraType = CameraFacing.Back;

					camera.StopPreview();
					camera.Release();
					camera = global::Android.Hardware.Camera.Open((int)cameraType);
					var parameters = camera.GetParameters();
					parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
					camera.SetParameters(parameters);
					camera.SetPreviewTexture(surfaceTexture);
					PrepareAndStartCamera();
				}
			}
			else
			{
				toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
				camera.StopPreview();
				camera.Release();

				camera = global::Android.Hardware.Camera.Open((int)cameraType);
				var parameters = camera.GetParameters();
				parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
				camera.SetParameters(parameters);
				camera.SetPreviewTexture(surfaceTexture);
				PrepareAndStartCamera();
			}
		}
Esempio n. 5
0
        private async void TakePhotoButtonTapped(object sender, EventArgs e)
        {
            var current = CrossConnectivity.Current.IsConnected;

            // check the internet connection to use the ResDiary API
            if (!current)
            {
                await App.Current.MainPage.DisplayAlert("Connection Error", "Please connect to the internet", "OK");
            }
            else
            {
                try
                {
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                    camera.SetParameters(parameters);
                    camera.StopPreview();
                    DialogService.ShowLoading("Scanning Logo");

                    // crop the image into the sqaure in order to make the prediction more accuracy
                    var image = CropImage(textureView.Bitmap);
                    using (var imageStream = new MemoryStream())
                    {
                        await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, imageStream);

                        image.Recycle();
                        imageBytes = imageStream.ToArray();
                    }

                    // send the image to CustomVision in form of bytes
                    var results = await CustomVisionService.PredictImageContentsAsync(imageBytes);

                    String resultInString = results.ToString();

                    if (resultInString.Length > 0)
                    {
                        // if the logo appeared more than 1 result than use the Geolocation
                        if (Geolocation.HasMoreOptions(resultInString))
                        {
                            DialogService.ShowLoading("More Restaurants Available");
                            resultInString = await Geolocation.GetCloserOptionAsync(resultInString);
                        }
                        var navigationPage = new NavigationPage(new RestaurantPage(resultInString));

                        DialogService.HideLoading();
                        camera.StartPreview();
                        await App.Current.MainPage.Navigation.PushModalAsync(navigationPage, true);
                    }
                    else
                    {
                        DialogService.HideLoading();
                        camera.StartPreview();

                        await App.Current.MainPage.DisplayAlert("Restaurant Not Found", "Please re-scan the Logo", "OK");
                    }
                }
                catch (Exception)
                {
                    camera.StopPreview();
                    camera.Release();
                    camera = global::Android.Hardware.Camera.Open((int)cameraType);
                    camera.SetPreviewTexture(surfaceTexture);

                    PrepareAndStartCamera();
                }
            }
        }