#

Gelöst: Fotos Laden in UWP ist sehr langsam

 

 

C# Code Example

 

Lösung 1:

Umstellen auf Async Laden von Images

Eine Verbesserung zeigt sich, wenn man von Image.SetSource  auf Image.SetSourceAscyn  wechselt

 

BitmapImage bitmapImage = new BitmapImage();

 

//*FAST in Win10

await bitmapImage.SetSourceAsync(imgThumbnail);

 

//*SLOW                  

//bitmapImage.SetSource(imgThumbnail);

 

tnImage.Source = bitmapImage;

 

Lösung 2:

Zusätzlich sollte man nach dem Laden von Images und UserControls kurz einen Delay einbauen.

await Task.Delay(1);

 

Ansonsten werden die Images nur langsam aufgebaut.

 

UserControl Laden in C#

           //----< @Loop: Files in Folder >----

            foreach (StorageFile file in await folder.GetFilesAsync())

            {

                //--< File >--

                Console.WriteLine(file.DisplayName);

 

                GridViewItem item = new GridViewItem();

                item.Margin = new Thickness(1);

                //

                if (file.ContentType.Contains("image") || file.ContentType.Contains("video"))

                {

                    //----< Ist Image >----

                    UcFile ucImage = new UcFile();

                    ucImage.file = file;

                    //item.Content = ucImage;

 

                    //< anfuegen >

                    item.Content = ucImage;

                    ctlFilesComputer.Items.Add(item);

                    //< anfuegen >

 

                    await Task.Delay(1);

                    //----</ Ist Image >----

 

                }

                //--</ File >--

            }

            //----</ @Loop: Files in Folder >-----

 

 

Image Control Laden in C#

 

private async void fl_load_Image()

        {

            //------------< fl_load_Image() >------------

            //--< show Image as Thumbnail >--

            try

            {

                //imgThumbnail = await _file.GetThumbnailAsync(ThumbnailMode.PicturesView, 100,ThumbnailOptions.ResizeThumbnail);

 

                if (_file.Path == "")

                {

                    //----< DCIM/Camera >----

                    imgThumbnail = await _file.GetThumbnailAsync(ThumbnailMode.SingleItem, 100, ThumbnailOptions.ResizeThumbnail);

 

 

                    if (_file.ContentType.Contains("video"))

                    {

                        icoVideo.Visibility = Windows.UI.Xaml.Visibility.Visible;

                    }

                    //----< DCIM/Camera >----

                }

                else

                {

                    if (_file.ContentType.Contains("image"))

                    {

                        imgThumbnail = await _file.GetThumbnailAsync(ThumbnailMode.PicturesView, 100, ThumbnailOptions.ResizeThumbnail);

                    }

                    else if (_file.ContentType.Contains("video"))

                    {

                        imgThumbnail = await _file.GetThumbnailAsync(ThumbnailMode.VideosView, 100, ThumbnailOptions.ResizeThumbnail);

                        icoVideo.Visibility = Windows.UI.Xaml.Visibility.Visible;

                    }

                    else

                    {

                        imgThumbnail = await _file.GetThumbnailAsync(ThumbnailMode.SingleItem, 100, ThumbnailOptions.ResizeThumbnail);

                    }

 

                }

                if (imgThumbnail != null)

                {

                    //-< show Image  >-

                    BitmapImage bitmapImage = new BitmapImage();

                    await bitmapImage.SetSourceAsync(imgThumbnail);

                    //bitmapImage.SetSource(imgThumbnail);

                    tnImage.Source = bitmapImage;

                    //-</ show Image >-

 

                    await Task.Delay(1);

                    //tbxTitle.Text = _file.DisplayName;

                }

                else

                {

                    Console.WriteLine("no thumbnail " + _file.Name);

                }

 

            }

            catch (Exception ex)

            {

                //clsDebug.debug_Exception(ex, "Error " + filename_cached);

                //HResult==-2147467261->.wmf

                await new MessageDialog(ex.Message).ShowAsync();

            }

            //--</ show Image as Thumbnail >--

 

           

 

            icoProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            //GridViewItem ucElement = (GridViewItem) Parent;

            //GridView ImageList = (GridView)ucElement.Parent;

 

            //ImageList.UpdateLayout();

            //------------</ fl_load_Image() >------------

        }

 

Mobile

.

0123movie.net