예제 #1
0
        private async Task updateUI(MyFilesModel item)
        {
            if (!item.ImageLoaded)
            {
                item.Bitmap = await MyFilesController.GetImage(item, (int)Window.Current.Bounds.Width);

                item.ImageLoaded = true;
            }
        }
예제 #2
0
        /// <summary>
        /// Retrieves a binary image and resizes it accordingly
        /// </summary>
        /// <param name="item">MyFilesModel object</param>
        /// <returns>resized BitmapSource</returns>
        public static async Task <BitmapSource> GetImage(MyFilesModel item, int w)
        {
            BitmapImage img = new BitmapImage();

            //ensure client created
            var client = await EnsureClient();

            //get the file stream
            using (Stream stream = await client.Files.GetById(item.Id).ToFile().DownloadAsync())
            {
                using (var memStream = new MemoryStream())
                {
                    await stream.CopyToAsync(memStream);

                    memStream.Position = 0;
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(memStream.AsRandomAccessStream());

                    using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
                    {
                        //first get original specs so we can scale the resize best
                        BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);

                        await enc.FlushAsync();

                        BitmapImage original = new BitmapImage();
                        original.SetSource(ras);
                        int height = original.PixelHeight;
                        int width  = original.PixelWidth;

                        //rewind and take a second pass...this time resizing
                        ras.Seek(0);
                        enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);

                        enc.BitmapTransform.ScaledHeight = (uint)(((double)height / (double)width) * w);
                        enc.BitmapTransform.ScaledWidth  = (uint)w;
                        await enc.FlushAsync();

                        img.SetSource(ras);
                    }
                }
            }

            return(img);
        }
예제 #3
0
        private void StackPanel_Tapped(object sender, TappedRoutedEventArgs e)
        {
            //get the contextual item tapped
            MyFilesModel item = (MyFilesModel)((StackPanel)sender).DataContext;

            //add to navigation stack
            (App.Current as App).NavigationStack.Add(item);

            //determine if this is a folder or file
            if (item.Type == "Folder")
            {
                //navigate to the detail page and pass the selected index
                Frame.Navigate(typeof(MainPage), (App.Current as App).Items.IndexOf((MyFilesModel)((StackPanel)sender).DataContext));
            }
            else
            {
                //navigate to the detail page and pass the selected index
                Frame.Navigate(typeof(ItemDetail), (App.Current as App).Items.IndexOf((MyFilesModel)((StackPanel)sender).DataContext));
            }
        }