Does UWP speed up image loading?

I am writing an application for the universal Windows platform where I need to upload some images for display in a list. Now my problem is that this download takes too much time for the user. Currently, I set the source images XAMLusing a bind, for example: {Binding Image}.

I only have access to full resolution images, so I would like to know if there is a way to make these images smaller before placing them in the user interface, so only a small image should remain in memory. Is there a way to customize the user interface element Imageso that it performs this resizing itself?

Also, is there any way to download these images lazily, because now my user interface is blocked from loading these images.

Edit: the code I use to upload my local images to mine Image(this is inside ListView.ItemTemplate):

<Image
    Grid.Row="0"
    Source="{Binding Image}"
    Stretch="Uniform"
    VerticalAlignment="Center"/>
+4
source share
2 answers

You can be lazy to upload and resize images using the converter. To the beginning of the converter you can use. In doing so, lazy loading is done for you. However, I have no example of resizing.

Converter Code

class LoadAttachmentAsyncConverter : IValueConverter
{
    public override object Convert(object value, Type targetType, object parameter, string language)
    {
        Task<BitmapImage> taskToExecute = GetImage(<some parameter>);
        //Possibly handle some other business logic
        return new NotifyTaskCompletion<BitmapImage>(taskToExecute);
    }

    public async Task<BitmapImage> GetImage(object someParameter) {
        BitmapImage image = new BitmapImage();
        //do (async stuff) to fill the image;
        return image;
    }
}

XAML code

<Image Source="{Binding Result}" DataContext="{Binding converterObjValue, Converter={StaticResource ConverterName}}"/>

: https://social.msdn.microsoft.com/Forums/en-US/490b9c01-db4b-434f-8aff-d5c495e67e55/how-to-crop-an-image-using-bitmaptransform?forum=winappswithcsharp

+2

.

    // You can also use BitmapImage directly, if you'd like to make reloading faster and don't care memory usage.
    private WeakReference<BitmapImage> image;

    public BitmapImage Image
    {
        get
        {
            BitmapImage image;
            if(this.image != null && this.image.TryGetTarget(out image))
                return image;
            image = new BitmapImage();
            this.image = new WeakReference<BitmapImage>(image);
            var ignore = Task.Run(()=>
            {
                //Load image here.
                //Don't forget to use Dispatcher while calling SetSourceAsync() or setting Source.
            });
            return image;
        }
    }
+1

All Articles