diff --git a/MapControl/WinUI/ImageLoader.WinUI.cs b/MapControl/WinUI/ImageLoader.WinUI.cs index a3a96a7d..c1c296c1 100644 --- a/MapControl/WinUI/ImageLoader.WinUI.cs +++ b/MapControl/WinUI/ImageLoader.WinUI.cs @@ -21,14 +21,23 @@ namespace MapControl { public static partial class ImageLoader { - public static async Task LoadImageAsync(BitmapDecoder decoder) + 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); +#else 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; } @@ -37,8 +46,13 @@ namespace MapControl // 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 + var image = new BitmapImage(); + await image.SetSourceAsync(stream); + return image; +#else return await LoadImageAsync(await BitmapDecoder.CreateAsync(stream)); +#endif } public static Task LoadImageAsync(Stream stream)