diff --git a/MapControl/Shared/ImageLoader.cs b/MapControl/Shared/ImageLoader.cs index a6574ca8..4d7b8e50 100644 --- a/MapControl/Shared/ImageLoader.cs +++ b/MapControl/Shared/ImageLoader.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -65,6 +66,14 @@ namespace MapControl return image; } + public static async Task LoadImageAsync(byte[] buffer) + { + using (var stream = new MemoryStream(buffer)) + { + return await LoadImageAsync(stream); + } + } + internal class HttpResponse { public byte[] Buffer { get; } diff --git a/MapControl/WPF/ImageLoader.WPF.cs b/MapControl/WPF/ImageLoader.WPF.cs index e06ab75e..e5d4e397 100644 --- a/MapControl/WPF/ImageLoader.WPF.cs +++ b/MapControl/WPF/ImageLoader.WPF.cs @@ -31,14 +31,6 @@ namespace MapControl return Task.FromResult(LoadImage(stream)); } - public static async Task LoadImageAsync(byte[] buffer) - { - using (var stream = new MemoryStream(buffer)) - { - return await LoadImageAsync(stream); - } - } - public static Task LoadImageAsync(string path) { return Task.Run(() => diff --git a/MapControl/WinUI/ImageLoader.WinUI.cs b/MapControl/WinUI/ImageLoader.WinUI.cs index c1c296c1..345900d5 100644 --- a/MapControl/WinUI/ImageLoader.WinUI.cs +++ b/MapControl/WinUI/ImageLoader.WinUI.cs @@ -21,32 +21,35 @@ namespace MapControl { public static partial class ImageLoader { - public static async Task LoadImageAsync(BitmapDecoder decoder) +#if false + public static async Task LoadImageAsync(BitmapDecoder decoder) { -#if USE_SOFTWAREBITMAP var image = new SoftwareBitmapSource(); var bitmap = await decoder.GetSoftwareBitmapAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, new BitmapTransform(), ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); await image.SetBitmapAsync(bitmap); + return image; + } #else + public static async Task LoadImageAsync(BitmapDecoder decoder) + { var image = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); var pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, new BitmapTransform(), ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); pixelData.DetachPixelData().CopyTo(image.PixelBuffer); -#endif return image; } - +#endif public static async Task LoadImageAsync(IRandomAccessStream stream) { // WinUI BitmapImage produces visual artifacts with Bing Maps Aerial (or all JPEG?) // images in a tile raster, where thin white lines may appear as gaps between tiles. // Alternatives are SoftwareBitmapSource or WriteableBitmap. -#if USE_BITMAPIMAGE +#if false var image = new BitmapImage(); await image.SetSourceAsync(stream); return image; @@ -60,22 +63,6 @@ namespace MapControl return LoadImageAsync(stream.AsRandomAccessStream()); } - public static async Task LoadImageAsync(IBuffer buffer) - { - using (var stream = new InMemoryRandomAccessStream()) - { - await stream.WriteAsync(buffer); - stream.Seek(0); - - return await LoadImageAsync(stream); - } - } - - public static Task LoadImageAsync(byte[] buffer) - { - return LoadImageAsync(buffer.AsBuffer()); - } - public static async Task LoadImageAsync(string path) { ImageSource image = null;