private void HandlePhoto(MediaFile photo)
        {
            if (photo == null)
            {
                return;
            }

            var currentStream = photo.GetStream();

            _bytes = ReadFully(currentStream);

            using (Stream stream = new MemoryStream(_bytes))
            {
                _imageBitmap = SKBitmap.Decode(stream);
            }

            var imageToView = new ImageFile()
            {
                PhotoBytes  = _bytes,
                ImageBitmap = _imageBitmap
            };

            var cameraPage = new CameraPage();

            cameraPage.Viewer.Initialize(imageToView);
            Navigation.PopAsync();
            Navigation.PushAsync(cameraPage);
        }
Esempio n. 2
0
        public FotoPage()
        {
            BindingContext = vm;
            Title          = "Fotos";

            bFoto = new Button
            {
                Text = "Tirar Foto",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            var camera = new CameraPage
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            Content = new StackLayout
            {
                Padding  = 30,
                Children =
                {
                    camera
                }
            };
        }
Esempio n. 3
0
 void OnChatting(object sender, System.EventArgs e)
 {
     cameraPage = null;
     cameraPage = new CameraPage();
     //Navigation.PushAsync((new CameraPage()/*_MachPage*/));
     Navigation.PushPopupAsync(cameraPage);
 }
Esempio n. 4
0
        async void TakePhotoButton_Clicked(object sender, System.EventArgs e)
        {
            var cameraPage = new CameraPage();

            cameraPage.OnPhotoResult += CameraPage_OnPhotoResult;
            await Navigation.PushModalAsync(cameraPage);
        }
        public void Setup()
        {
            _browserAccess = new BrowserAccess();
            _driver        = _browserAccess.Driver;
            _baseUrl       = _browserAccess.BaseUrl;

            _homePage   = new HomePage(_driver);
            _cameraPage = new CameraPage(_driver);
        }
Esempio n. 6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e)
        {
            base.OnElementChanged(e);

            page = (CameraPage)e.NewElement;

            SetupUserInterface();
            SetupEventHandlers();
        }
Esempio n. 7
0
 /// <summary>
 /// evento del boton capturar, hace una llamada a la pantalla camara (se renderiza nativamente según el dispositivo)
 /// cualquier cambio a la camara es necesaria hacerla en CamaraPageRenderer.cs contenido en el modulo de .droid y .iOS respectivamente
 /// </summary>
 /// <param name="sender">objeto que hace referencia al evento</param>
 /// <param name="e">argumentos que son posibles de obtener apartir del objeto que hace llamada al evento</param>
 async void OCR_Clicked(object sender, System.EventArgs e)
 {
     if (CrossConnectivity.Current.IsConnected)
     {
         var cameraPage = new CameraPage();
         cameraPage.OnPhotoResult += CameraPage_OnPhotoResult;
         //await CameraPage_OnPhotoResult();
         await Navigation.PushModalAsync(cameraPage);
     }
     else
     {
         await DisplayAlert("Error de conexión", "Es necesario estar conectado a internet para acceder este servicio", "Ok");
     }
 }
Esempio n. 8
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            //Set bool variable to use camera image
            isStream = true;

            //Create a new object for the page
            CameraPage camera = new CameraPage();

            btnCapture.IsEnabled = true;
            btnOCR.IsEnabled     = false;

            //Navigate to the new page
            frame.NavigationService.Navigate(camera);
        }
Esempio n. 9
0
        private Action <object> AddImageAction()
        {
            return(async(obj) =>
            {
                var results = await DependencyService.Get <IPermissions>().VerifyPermissionsAsync(false, PermissionType.Camera);

                if (results == null || results[PermissionType.Camera] != PermissionStatus.Granted)
                {
                    return;
                }

                string[] actions = null;
                if (!String.IsNullOrEmpty(_contact.ProfileImage))
                {
                    actions = new string[] { "Retake Photo", "Remove Photo" };
                    string action = await _page.DisplayActionSheet("Profile Photo", "Cancel", null, actions);

                    if (!String.IsNullOrEmpty(action) && !"Cancel".Equals(action))
                    {
                        if (action == "Retake Photo")
                        {
                            CameraPage cameraPage = new CameraPage(CameraOperationType.Profile);
                            cameraPage.PictureTaken += _page.CameraPictureTaken;

                            HomePage.Instance.PushCameraPage(cameraPage);
                        }
                        else if (action == "Remove Photo")
                        {
                            if (File.Exists(_contact.ProfileImage))
                            {
                                File.Delete(_contact.ProfileImage);
                            }

                            _contact.ProfileImage = "";
                            SetContact();
                            _page.ContactModified = true;
                            return;
                        }
                    }
                }
                else
                {
                    CameraPage cameraPage = new CameraPage(CameraOperationType.Profile);
                    cameraPage.PictureTaken += _page.CameraPictureTaken;

                    HomePage.Instance.PushCameraPage(cameraPage);
                }
            });
        }
Esempio n. 10
0
        private void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            CameraPage cameraPage = new CameraPage();

            Bitmap taken = cameraPage.GenerateTakenImage();

            if (taken != null)
            {
                outputPage.imgOutput.Source = ImageUtils.ImageSourceFromBitmap(taken);
            }

            //Declare that image is used
            isImageLoaded = true;

            //Enable the detect button
            btnOCR.IsEnabled = true;

            //Clear the frame
            frame.Content = outputPage;
        }
        //handles when the preview is tapped (to take a picture for classification)
        public async void OnCameraPreviewTapped(object sender, EventArgs e)
        {
            if (ready)
            {
                ready = false;
                AVCaptureStillImageOutput output = new AVCaptureStillImageOutput
                {
                    OutputSettings = new NSDictionary()
                };
                uiCameraPreview.CaptureSession.AddOutput(output);
                System.Threading.Thread.Sleep(70);
                var videoConnection = output.ConnectionFromMediaType(AVMediaType.Video);
                var sampleBuffer    = await output.CaptureStillImageTaskAsync(videoConnection);

                var jpegImageAsNSData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
                var jpegAsByteArray   = jpegImageAsNSData.ToArray();
                //send to camera page to send image to aws
                CameraPage.TakePhoto(jpegAsByteArray);
                uiCameraPreview.CaptureSession.RemoveOutput(output);
                ready = true;
            }
        }
Esempio n. 12
0
        private void button_resetOffsets_Click(object sender, RoutedEventArgs e)
        {
            cc2d.border_tools1.Visibility = Visibility.Collapsed;
            cc2d.border_tools2.Visibility = Visibility.Visible;

            ((Image)cc2d.button_switchToCamera.Content).Source =
                new BitmapImage(
                    new Uri("pack://application:,,,/Cad2D;component/Resources/tick.png",
                    UriKind.Absolute));
            cc2d.btn_sendToPlc_back.Visibility = Visibility.Collapsed;

            cc2d.pagesStack.Push(this);
            CameraPage cp = new CameraPage();
            cc2d.contentControl.Content = cp;
            cp.start();
        }
Esempio n. 13
0
        public NavigationPage FetchMainUI()
        {
            momentListPage = new MomentListPage();
            cameraPage     = new CameraPage();
            //cameraPreviewPage = new CameraPreviewPage();
            profilePage = new ProfilePage();

            bottomBarPage = new BottomBarPage();
            bottomBarPage.BarBackgroundColor = Color.Pink;

            bottomBarPage.Children.Add(momentListPage);
            momentListPage.Title = "Moments";
            momentListPage.Icon  = (FileImageSource)ImageSource.FromFile("earth.png");
            //momentListPage.SetTabColor(Color.FromHex("#5D4037"));

            bottomBarPage.Children.Add(cameraPage);
            cameraPage.Title = "Camera";
            cameraPage.Icon  = (FileImageSource)ImageSource.FromFile("camera.png");
            //cameraPage.SetTabColor(Color.FromHex("#5D4037"));

            bottomBarPage.Children.Add(profilePage);
            profilePage.Title = "Profile";
            profilePage.Icon  = (FileImageSource)ImageSource.FromFile("face.png");
            //profilePage.SetTabColor(Color.FromHex("#5D4037"));


            var navigationPage = new NavigationPage(bottomBarPage);

            NavigationPage.SetHasNavigationBar(bottomBarPage, false);
            //NavigationPage navigationPage = null;

            //string[] tabTitles = { "Favorites", "Friends", "Nearby", "Recents", "Restaurants" };
            //string[] tabColors = { null, "#5D4037", "#7B1FA2", "#FF5252", "#FF9800" };

            //for (int i = 0; i < tabTitles.Length; ++i)
            //{
            //    string title = tabTitles[i];
            //    string tabColor = tabColors[i];

            //FileImageSource icon = (FileImageSource)ImageSource.FromFile(string.Format("ic_{0}.png", title.ToLowerInvariant()));

            //    // create tab page
            //    var tabPage = new TabPage()
            //    {
            //        Title = title,
            //        Icon = icon
            //    };

            //    // set tab color
            //    if (tabColor != null)
            //    {
            //        tabPage.SetTabColor(Color.FromHex(tabColor));
            //    }

            //    // set label based on title
            //    tabPage.UpdateLabel();

            //    // add tab pag to tab control
            //    bottomBarPage.Children.Add(tabPage);
            //}

            return(navigationPage);
        }
        public void OpenCamera()
        {
            IsOpen = false;

            Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.25), async() =>
            {
                var cameraSettings = IoC.Get <IStateService>().GetCameraSettings();
                if (cameraSettings != null && !cameraSettings.External)
                {
                    SystemTray.IsVisible = false;
                    var frame            = Application.Current.RootVisual as PhoneApplicationFrame;

                    double width              = 0.0;
                    double height             = 0.0;
                    PhoneApplicationPage page = null;
                    if (frame != null)
                    {
                        page = frame.Content as PhoneApplicationPage;
                        if (page != null)
                        {
                            width  = page.ActualWidth;
                            height = page.ActualHeight;
                            page.IsHitTestVisible = false;
                            //page.Visibility = Visibility.Collapsed;
                            page.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
                        }
                    }

                    var cameraPage = new CameraPage();

                    var binding    = new Binding();
                    binding.Source = page;
                    binding.Path   = new PropertyPath("Orientation");
                    cameraPage.SetBinding(CameraPage.ParentPageOrientationProperty, binding);

                    cameraPage.Width  = width;
                    cameraPage.Height = height;

                    var telegramMessageBox = new TelegramMessageBox {
                        IsFullScreen = true
                    };
                    telegramMessageBox.Content = cameraPage;

                    var photoCaptured         = false;
                    cameraPage.PhotoCaptured += (sender, args) =>
                    {
                        if (args.File != null)
                        {
                            _sendPhotosAction.SafeInvoke(new ReadOnlyCollection <StorageFile>(new[] { args.File }));
                        }
                        else
                        {
                            photoCaptured = true;
                            telegramMessageBox.Dismiss();
                        }
                    };
                    cameraPage.VideoCaptured += (sender, args) =>
                    {
                        telegramMessageBox.Dismiss();

                        var dialogDetails = page as IDialogDetailsView;
                        if (dialogDetails != null)
                        {
                            dialogDetails.CreateBitmapCache(() => { });
                        }

                        Execute.BeginOnUIThread(TimeSpan.FromSeconds(1.0), () => _sendVideoAction.SafeInvoke(args.File));
                    };
                    telegramMessageBox.Show();
                    telegramMessageBox.Dismissing += (sender, args) =>
                    {
                    };
                    telegramMessageBox.Dismissed += (sender, args) =>
                    {
                        SystemTray.IsVisible = true;

                        frame = Application.Current.RootVisual as PhoneApplicationFrame;
                        if (frame != null)
                        {
                            page = frame.Content as PhoneApplicationPage;
                            if (page != null)
                            {
                                page.IsHitTestVisible = true;
                                //page.Visibility = Visibility.Visible;
                                page.SupportedOrientations = SupportedPageOrientation.Portrait;
                            }
                        }

                        cameraPage.ClearValue(CameraPage.ParentPageOrientationProperty);
                        if (!photoCaptured)
                        {
                            cameraPage.Dispose();
                        }
                    };
                }
                else
                {
                    if (Environment.OSVersion.Version.Major >= 10)
                    {
                        object ccu  = null;
                        var _type10 = Type.GetType("Windows.Media.Capture.CameraCaptureUI, Windows, ContentType=WindowsRuntime");
                        if (_type10 != null)
                        {
                            ccu = Activator.CreateInstance(_type10);
                        }
                        if (ccu == null)
                        {
                            return;
                        }
                        var mode       = CameraCaptureUIMode.Photo;
                        var modeType   = Type.GetType("Windows.Media.Capture.CameraCaptureUIMode, Windows, ContentType=WindowsRuntime");
                        object modeVal = Enum.ToObject(modeType, mode);
                        try
                        {
                            var file = await(Windows.Foundation.IAsyncOperation <StorageFile>) _type10.GetRuntimeMethod("CaptureFileAsync", new Type[] { modeType }).Invoke(ccu, new object[] { modeVal });
                            if (file != null)
                            {
                                _sendPhotosAction.SafeInvoke(new ReadOnlyCollection <StorageFile>(new[] { file }));
                            }
                        }
                        catch (Exception ex)
                        {
                            Execute.ShowDebugMessage("CameraCaptureTask.OnCompleted ex " + ex);
                        }
                    }
                    else
                    {
                        ((App)Application.Current).ChooseFileInfo = new ChooseFileInfo(DateTime.Now);
                        var task        = new CameraCaptureTask();
                        task.Completed += (o, e) =>
                        {
                            if (e.TaskResult != TaskResult.OK)
                            {
                                return;
                            }

                            try
                            {
                                var getFileTask = StorageFile.GetFileFromPathAsync(e.OriginalFileName).AsTask();
                                var file        = getFileTask.Result;
                                App.Photos      = new ReadOnlyCollection <StorageFile>(new[] { file });
                            }
                            catch (Exception ex)
                            {
                                Execute.ShowDebugMessage("CameraCaptureTask.OnCompleted ex " + ex);
                            }
                        };
                        task.Show();
                    }
                }
            });
        }
 public AutoFocusCallback(CameraPage cameraPageRef, float xPoint, float yPoint)
 {
     cameraPage = cameraPageRef;
     tapX       = xPoint;
     tapY       = yPoint;
 }
Esempio n. 16
0
 public App()
 {
     // The root page of your application
     MainPage = new CameraPage();
     ComputerVision.MakeRequest();
 }
Esempio n. 17
0
        //private const int BUTTON_BORDER_WIDTH = 1;
        //private const int BUTTON_HEIGHT = 88;
        //private const int BUTTON_HEIGHT_WP = 144;
        //private const int BUTTON_HALF_HEIGHT = 44;
        //private const int BUTTON_HALF_HEIGHT_WP = 72;
        //private const int BUTTON_WIDTH = 88;
        //private const int BUTTON_WIDTH_WP = 144;

        //private AbsoluteLayout bodyLayout;
        //private StackLayout bottomLayout;
        //private StackLayout descriptionLayout;
        //private Image image = new Image();
        //private ActivityIndicator indicator = new ActivityIndicator();
        //private Label imageDescription = new Label ();

        //private byte[] imageBuffer;
        //private bool faceDetected = false;
        //private bool emotionDetected = false;

        public App()
        {
//			bodyLayout = new AbsoluteLayout ();
//			bodyLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
//			bodyLayout.VerticalOptions = LayoutOptions.CenterAndExpand;
//			bodyLayout.Children.Add (image);

//			descriptionLayout = new StackLayout ();
//			descriptionLayout.IsVisible = false;
//			descriptionLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
//			descriptionLayout.VerticalOptions = LayoutOptions.CenterAndExpand;
//			imageDescription.TextColor = Color.Black;
//			imageDescription.HorizontalOptions = LayoutOptions.CenterAndExpand;
//			imageDescription.HorizontalTextAlignment = TextAlignment.Center;
//			imageDescription.Text = "descrivimi l'immagine";
//			var describeTap = new TapGestureRecognizer ();
//			describeTap.Tapped += async (sender, e) => {
//				OnStartLongProcess ();
//				var visionClient = new ComputerVisionClient ();
//				var result = await visionClient.RecognizeAsync (new MemoryStream (imageBuffer));
//				imageDescription.Text = result.description.captions.FirstOrDefault()?.text;
//				OnEndLongProcess ();
//			};
//			imageDescription.GestureRecognizers.Add(describeTap);
//			descriptionLayout.Children.Add (imageDescription);

//			bottomLayout = new StackLayout ();
//			bottomLayout.Orientation = StackOrientation.Horizontal;
//			bottomLayout.HorizontalOptions = LayoutOptions.Center;

//			var button = new Button ()
//			{
//				Image = "Camera-50.png",
//				BackgroundColor = Color.Blue,
//				BorderColor = Color.White,
//				TextColor = Color.White,
//				BorderWidth = BUTTON_BORDER_WIDTH,
//				BorderRadius = Device.OnPlatform(BUTTON_HALF_HEIGHT, BUTTON_HALF_HEIGHT, BUTTON_HALF_HEIGHT_WP),
//				HeightRequest = Device.OnPlatform(BUTTON_HEIGHT, BUTTON_HEIGHT, BUTTON_HEIGHT_WP),
//				MinimumHeightRequest = Device.OnPlatform(BUTTON_HEIGHT, BUTTON_HEIGHT, BUTTON_HEIGHT_WP),
//				WidthRequest = Device.OnPlatform(BUTTON_WIDTH, BUTTON_WIDTH, BUTTON_WIDTH_WP),
//				MinimumWidthRequest = Device.OnPlatform(BUTTON_WIDTH, BUTTON_WIDTH, BUTTON_WIDTH_WP),
//				HorizontalOptions = LayoutOptions.Center,
//				VerticalOptions = LayoutOptions.Center
//			};
//			button.Clicked += TakePictureButtonClicked;

////			var button2 = new Button ()
////			{
////				Image = "Camera-50.png",
////				BackgroundColor = Color.Blue,
////				BorderColor = Color.White,
////				TextColor = Color.White,
////				BorderWidth = BUTTON_BORDER_WIDTH,
////				BorderRadius = Device.OnPlatform(BUTTON_HALF_HEIGHT, BUTTON_HALF_HEIGHT, BUTTON_HALF_HEIGHT_WP),
////				HeightRequest = Device.OnPlatform(BUTTON_HEIGHT, BUTTON_HEIGHT, BUTTON_HEIGHT_WP),
////				MinimumHeightRequest = Device.OnPlatform(BUTTON_HEIGHT, BUTTON_HEIGHT, BUTTON_HEIGHT_WP),
////				WidthRequest = Device.OnPlatform(BUTTON_WIDTH, BUTTON_WIDTH, BUTTON_WIDTH_WP),
////				MinimumWidthRequest = Device.OnPlatform(BUTTON_WIDTH, BUTTON_WIDTH, BUTTON_WIDTH_WP),
////				HorizontalOptions = LayoutOptions.Center,
////				VerticalOptions = LayoutOptions.Center
////			};
////			button2.Clicked += SpeechButtonClicked;
//			bottomLayout.Children.Add (button);
////			bottomLayout.Children.Add (button2);

//			var imageTap = new TapGestureRecognizer ();
//			imageTap.Tapped += async (sender, e) => {

//				OnStartLongProcess ();
//				if (!faceDetected){
//					faceDetected = true;
//					await DetectFace (new MemoryStream (imageBuffer));
//				} else if (!emotionDetected) {
//					emotionDetected = true;
//					await RecognizeEmotion(new MemoryStream(imageBuffer));
//				}
//				OnEndLongProcess ();

//			};
//			image.GestureRecognizers.Add (imageTap);

//			indicator.HorizontalOptions = LayoutOptions.CenterAndExpand;
//			indicator.VerticalOptions = LayoutOptions.CenterAndExpand;

//			var content = new Grid ();
//			content.RowDefinitions.Add (new RowDefinition () { Height = new GridLength(1, GridUnitType.Star) });
//			content.RowDefinitions.Add (new RowDefinition () { Height = 100 });
//			content.RowDefinitions.Add (new RowDefinition () { Height = 100 });
//			content.Children.Add (bodyLayout);
//			content.Children.Add (descriptionLayout);
//			content.Children.Add (bottomLayout);
//			content.Children.Add (indicator);

//			Grid.SetRow (bodyLayout, 0);
//			Grid.SetRow (descriptionLayout, 1);
//			Grid.SetRow (bottomLayout, 2);
//			Grid.SetRow (indicator, 0);
//			Grid.SetRowSpan (indicator, 3);

            MainPage = new CameraPage();
        }
Esempio n. 18
0
      protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
      {
          IsCamera = CameraPage.IsCamera;
          IsVideo  = VideoPlayerPage.IsVideo;

          base.OnActivityResult(requestCode, resultCode, data);
          if (requestCode == PickImageId)
          {
              if ((resultCode == Result.Ok) && (data != null))
              {
                  // Set the filename as the completion of the Task
                  PickImageTaskCompletionSource.SetResult(data.DataString);
              }
              else
              {
                  PickImageTaskCompletionSource.SetResult(null);
              }
          }
          if (IsCamera)
          {
              Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
              Uri    contentUri      = Uri.FromFile(AppClass._file);
              mediaScanIntent.SetData(contentUri);
              SendBroadcast(mediaScanIntent);

              //int height = Resources.DisplayMetrics.HeightPixels;
              int width = Resources.DisplayMetrics.WidthPixels;
              AppClass.bitmap = AppClass._file.Path.LoadAndResizeBitmap(width, width);

              byte[] bitmapData = new byte[0];

              if (AppClass.bitmap != null)
              {
                  using (var stream = new MemoryStream())
                  {
                      AppClass.bitmap.Compress(Bitmap.CompressFormat.Png, 50, stream);
                      bitmapData = stream.ToArray();
                  }

                  AppClass.bitmap = null;
              }

              GC.Collect();

              CameraPage.Cameraimage(bitmapData);
          }

          if (true)
          {
              if (requestCode == 1)
              {
                  if (resultCode == Result.Ok)
                  {
                      if (data.Data != null)
                      {
                          Android.Net.Uri uri = data.Data;

                          int orientation       = getOrientation(uri);
                          BitmapWorkerTask task = new BitmapWorkerTask(this.ContentResolver, uri);
                          task.Execute(orientation);
                      }
                  }
              }
          }
      }
Esempio n. 19
0
        public App()
        {
            InitializeComponent();

            MainPage = new CameraPage();
        }
Esempio n. 20
0
 private void HandlePopupCameraPage(CameraPage sender, NativeNavigationArgs args)
 {
     this.activity.Finish();
 }