Esempio n. 1
0
        public async Task <IRandomAccessStream> GetThumbnailImage(IRandomAccessStream stream, int width, int height, bool smartCropping = true)
        {
            var response = await _client.GetThumbnailAsync(stream.AsStreamForRead(), width, height, smartCropping);

            var responseStream = new MemoryStream(response);

            return(responseStream.AsRandomAccessStream());
        }
Esempio n. 2
0
        /// <summary>
        /// Function to browse for an image and get a thumbnail for it. Thumbnail size is set to 250x250 pixels
        /// </summary>
        /// <param name="obj"></param>
        private async void BrowseAndAnalyze(object obj)
        {
            var openDialog = new Microsoft.Win32.OpenFileDialog();

            openDialog.Filter = "Image Files(*.jpg, *.gif, *.bmp, *.png)|*.jpg;*.jpeg;*.gif;*.bmp;*.png";
            bool?result = openDialog.ShowDialog();

            if (!(bool)result)
            {
                return;
            }

            string filePath = openDialog.FileName;

            Uri         fileUri = new Uri(filePath);
            BitmapImage image   = new BitmapImage(fileUri);

            image.CacheOption = BitmapCacheOption.None;
            image.UriSource   = fileUri;

            ImageSource = image;

            try
            {
                using (Stream fileStream = File.OpenRead(filePath))
                {
                    byte[] thumbnailResult = await _visionClient.GetThumbnailAsync(fileStream, 250, 250);

                    if (thumbnailResult != null && thumbnailResult.Length != 0)
                    {
                        CreateThumbnail(thumbnailResult);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Failed to analyze image: {ex.Message}");
            }
        }