mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Image loading with cancellation
This commit is contained in:
parent
81eabef257
commit
69bba213f0
13 changed files with 103 additions and 88 deletions
|
|
@ -4,6 +4,7 @@ using Avalonia.Media.Imaging;
|
|||
using Avalonia.Platform;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -38,17 +39,18 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
internal static async Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
|
||||
internal static async Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
WriteableBitmap mergedBitmap = null;
|
||||
var p1 = 0d;
|
||||
var p2 = 0d;
|
||||
|
||||
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); })));
|
||||
LoadImageAsync(uri1, new Progress<double>(p => { p1 = p; progress.Report((p1 + p2) / 2d); }), cancellationToken),
|
||||
LoadImageAsync(uri2, new Progress<double>(p => { p2 = p; progress.Report((p1 + p2) / 2d); }), cancellationToken));
|
||||
|
||||
if (images.Length == 2 &&
|
||||
if (!cancellationToken.IsCancellationRequested &&
|
||||
images.Length == 2 &&
|
||||
images[0] is Bitmap bitmap1 &&
|
||||
images[1] is Bitmap bitmap2 &&
|
||||
bitmap1.PixelSize.Height == bitmap2.PixelSize.Height &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue