Ejemplo n.º 1
0
        private async void takePhoto_Clicked(object sender, EventArgs e)
        {
            if (IsSpeaking)
            {
                HandleSpeakCancel();
            }
            await CrossMedia.Current.Initialize();

            try
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", "No camera available.", "OK");

                    return;
                }
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory     = "Sample",
                    Name          = "xamarin.jpg",
                    PhotoSize     = Plugin.Media.Abstractions.PhotoSize.Large,
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear
                });

                if (file == null)
                {
                    return;
                }
                //MakeOCRRequest(file.Path);
                this.activity.IsRunning = true;
                var          imagefilestream = ImagetoBasestr(file.Path);
                GoogleVision googleVision    = new GoogleVision(Settings.GKey);
                var          result          = await googleVision.RequestAnotate(imagefilestream);

                imgSelected.Source = Xamarin.Forms.ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return(stream);
                });
                ShowResult(result);
                file.Dispose();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
        }
Ejemplo n.º 2
0
        private async void pickPhoto_Clicked(object sender, EventArgs e)
        {
            if (IsSpeaking)
            {
                HandleSpeakCancel();
            }
            await CrossMedia.Current.Initialize();

            try
            {
                var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Large
                });

                if (file == null)
                {
                    return;
                }
                //MakeOCRRequest(file.Path);
                this.activity.IsRunning = true;
                var          imagefilestream = ImagetoBasestr(file.Path);
                GoogleVision googleVision    = new GoogleVision(Settings.GKey);
                var          result          = await googleVision.RequestAnotate(imagefilestream);

                imgSelected.Source = Xamarin.Forms.ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return(stream);
                });
                ShowResult(result);
                file.Dispose();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
        }