Пример #1
0
        async Task OnAddNewImage()
        {
            ImageDescription = string.Empty;
            if (CrossMedia.Current.IsPickPhotoSupported)
            {
                var image = await CrossMedia.Current.PickPhotoAsync();

                if (image != null)
                {
                    var stream = image.GetStream();
                    MyImageSource = ImageSource.FromStream(() =>
                    {
                        return(stream);
                    });
                    try
                    {
                        ProgressVisible = true;
                        var result = await _cognitiveClient.GetImageDescription(image.GetStream());

                        image.Dispose();
                        foreach (string tag in result.Description.Tags)
                        {
                            ImageDescription = ImageDescription + "\n" + tag;
                        }
                    }
                    catch (Microsoft.ProjectOxford.Vision.ClientException ex)
                    {
                        ImageDescription = ex.Message;
                    }
                    ProgressVisible = false;
                }
            }
        }
        async Task OnAddNewImage()
        {
            var image = await CrossMedia.Current.PickPhotoAsync();

            if (image != null)
            {
                var stream = image.GetStream();
                MyImageSource = new BitmapImage(new Uri(image.Path, UriKind.Absolute));
                var analysisResult = await _cognitiveClient.GetImageDescription(stream);

                string tags = "";
                analysisResult.Description.Tags.ToList().ForEach(t => tags = tags + "\n" + t);
                AnalysisResult = tags;
            }
        }
        private async Task OnAddNewImage()
        {
            ImageDescription = string.Empty;
            if (CrossMedia.Current.IsPickPhotoSupported)
            {
                var image = await CrossMedia.Current.PickPhotoAsync();

                if (image != null)
                {
                    var stream = image.GetStream();
                    MyImageSource = ImageSource.FromStream(() =>
                    {
                        return(stream);
                    });
                    try
                    {
                        ProgressVisible = true;
                        var result = await _cognitiveClient.GetImageDescription(image.GetStream());

                        image.Dispose();

                        Person person = new Person()
                        {
                            Name    = string.Empty,
                            Surname = string.Empty,
                            //Information = result.Description.Tags
                        };

                        result.Description.Captions.ToList().ForEach(f => { person.Information.Add(f.Text); });

                        foreach (string tag in person.Information)
                        {
                            ImageDescription = ImageDescription + "\n" + tag;
                        }
                    }
                    //Microsoft.ProjectOxford.Vision.ClientException
                    catch (Exception ex)
                    {
                        ImageDescription = ex.Message;
                    }
                    ProgressVisible = false;
                }
            }
        }