ImageLoader

This commit is contained in:
ClemensFischer 2025-09-03 22:03:20 +02:00
parent dfe3201625
commit 55d1ee933c
3 changed files with 27 additions and 23 deletions

View file

@ -12,7 +12,7 @@ namespace MapControl
{
public static IImage LoadImage(Uri uri)
{
return null;
throw new NotSupportedException();
}
public static IImage LoadImage(Stream stream)
@ -25,19 +25,21 @@ namespace MapControl
return Task.FromResult(LoadImage(stream));
}
public static Task<IImage> LoadImageAsync(string path)
public static async Task<IImage> LoadImageAsync(string path)
{
if (!File.Exists(path))
{
return Task.FromResult<IImage>(null);
}
IImage image = null;
if (File.Exists(path))
{
using (var stream = File.OpenRead(path))
{
return LoadImageAsync(stream);
image = await LoadImageAsync(stream);
}
}
return image;
}
internal static async Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
WriteableBitmap mergedBitmap = null;

View file

@ -31,6 +31,14 @@ namespace MapControl
HttpClient.DefaultRequestHeaders.Add("User-Agent", $"XAML-Map-Control/{typeof(ImageLoader).Assembly.GetName().Version}");
}
public static async Task<ImageSource> LoadImageAsync(byte[] buffer)
{
using (var stream = new MemoryStream(buffer))
{
return await LoadImageAsync(stream);
}
}
public static async Task<ImageSource> LoadImageAsync(Uri uri, IProgress<double> progress = null)
{
ImageSource image = null;
@ -67,14 +75,6 @@ namespace MapControl
return image;
}
public static async Task<ImageSource> LoadImageAsync(byte[] buffer)
{
using (var stream = new MemoryStream(buffer))
{
return await LoadImageAsync(stream);
}
}
internal class HttpResponse
{
public byte[] Buffer { get; }

View file

@ -32,19 +32,21 @@ namespace MapControl
return Task.FromResult(LoadImage(stream));
}
public static Task<ImageSource> LoadImageAsync(string path)
public static async Task<ImageSource> LoadImageAsync(string path)
{
if (!File.Exists(path))
{
return Task.FromResult<ImageSource>(null);
}
ImageSource image = null;
if (File.Exists(path))
{
using (var stream = File.OpenRead(path))
{
return LoadImageAsync(stream);
image = await LoadImageAsync(stream);
}
}
return image;
}
internal static async Task<ImageSource> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
WriteableBitmap mergedBitmap = null;