Avalonia ImageLoader

This commit is contained in:
ClemensFischer 2024-05-22 16:15:29 +02:00
parent 3cc93c7460
commit 4867d52013
5 changed files with 69 additions and 36 deletions

View file

@ -38,13 +38,13 @@ namespace MapControl
public static Task<ImageSource> LoadImageAsync(string path)
{
if (!File.Exists(path))
{
return Task.FromResult<ImageSource>(null);
}
return Task.Run(() =>
{
if (!File.Exists(path))
{
return null;
}
using (var stream = File.OpenRead(path))
{
return LoadImage(stream);
@ -54,19 +54,9 @@ namespace MapControl
internal static async Task<ImageSource> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
var images = await LoadImagesAsync(uri1, uri2, progress);
WriteableBitmap image = null;
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); });
}
var images = await Task.WhenAll(LoadImageAsync(uri1, progress1), LoadImageAsync(uri2, progress2));
if (images.Length == 2 &&
images[0] is BitmapSource image1 &&