ImageLoader

This commit is contained in:
ClemensFischer 2025-01-02 10:48:51 +01:00
parent 61a772d02b
commit 5282046c31
3 changed files with 11 additions and 18 deletions

View file

@ -43,8 +43,12 @@ namespace MapControl
internal static async Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
WriteableBitmap mergedBitmap = null;
var p1 = 0d;
var p2 = 0d;
var images = await LoadImagesAsync(uri1, uri2, progress);
var images = await Task.WhenAll(
LoadImageAsync(uri1, new Progress<double>(p => { p1 = p; progress.Report((p1 + p2) / 2d); })),
LoadImageAsync(uri2, new Progress<double>(p => { p2 = p; progress.Report((p1 + p2) / 2d); })));
if (images.Length == 2 &&
images[0] is Bitmap bitmap1 &&

View file

@ -157,21 +157,5 @@ namespace MapControl
return buffer;
}
private static Task<ImageSource[]> LoadImagesAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
IProgress<double> progress1 = null;
IProgress<double> progress2 = null;
if (progress != null)
{
var p1 = 0d;
var p2 = 0d;
progress1 = new Progress<double>(p => { p1 = p; progress.Report((p1 + p2) / 2d); });
progress2 = new Progress<double>(p => { p2 = p; progress.Report((p1 + p2) / 2d); });
}
return Task.WhenAll(LoadImageAsync(uri1, progress1), LoadImageAsync(uri2, progress2));
}
}
}

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
@ -55,8 +56,12 @@ namespace MapControl
internal static async Task<ImageSource> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
WriteableBitmap mergedBitmap = null;
var p1 = 0d;
var p2 = 0d;
var images = await LoadImagesAsync(uri1, uri2, progress);
var images = await Task.WhenAll(
LoadImageAsync(uri1, new Progress<double>(p => { p1 = p; progress.Report((p1 + p2) / 2d); })),
LoadImageAsync(uri2, new Progress<double>(p => { p2 = p; progress.Report((p1 + p2) / 2d); })));
if (images.Length == 2 &&
images[0] is BitmapSource bitmap1 &&