Update ImageLoader.WinUI.cs

This commit is contained in:
ClemensFischer 2023-08-17 19:55:37 +02:00
parent bd9e7866f5
commit d2fc65f133

View file

@ -22,6 +22,8 @@ namespace MapControl
{ {
public static partial class ImageLoader public static partial class ImageLoader
{ {
private static readonly BitmapTransform defaultBitmapTransform = new BitmapTransform();
public static async Task<ImageSource> LoadImageAsync(IRandomAccessStream stream) public static async Task<ImageSource> LoadImageAsync(IRandomAccessStream stream)
{ {
// WinUI BitmapImage produces visual artifacts with Bing Maps Aerial (or all JPEG?) // WinUI BitmapImage produces visual artifacts with Bing Maps Aerial (or all JPEG?)
@ -30,7 +32,12 @@ namespace MapControl
var image = new SoftwareBitmapSource(); var image = new SoftwareBitmapSource();
var decoder = await BitmapDecoder.CreateAsync(stream); var decoder = await BitmapDecoder.CreateAsync(stream);
using (var bitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied)) using (var bitmap = await decoder.GetSoftwareBitmapAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
defaultBitmapTransform,
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage))
{ {
await image.SetBitmapAsync(bitmap); await image.SetBitmapAsync(bitmap);
} }
@ -50,8 +57,6 @@ namespace MapControl
{ {
using (var stream = new MemoryStream(buffer)) using (var stream = new MemoryStream(buffer))
{ {
// Method call must be awaited before closing the stream.
//
return await LoadImageAsync(stream); return await LoadImageAsync(stream);
} }
} }
@ -121,7 +126,7 @@ namespace MapControl
var pixelData = await decoder.GetPixelDataAsync( var pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8, BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight, BitmapAlphaMode.Straight,
new BitmapTransform(), defaultBitmapTransform,
ExifOrientationMode.IgnoreExifOrientation, ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage); ColorManagementMode.DoNotColorManage);