From 2094facc5e47e234cd36d45beb02f5a464adc71e Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 18 Aug 2023 09:07:18 +0200 Subject: [PATCH] Update ImageLoader.WinUI.cs --- MapControl/WinUI/ImageLoader.WinUI.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/MapControl/WinUI/ImageLoader.WinUI.cs b/MapControl/WinUI/ImageLoader.WinUI.cs index d34108dd..694b28ff 100644 --- a/MapControl/WinUI/ImageLoader.WinUI.cs +++ b/MapControl/WinUI/ImageLoader.WinUI.cs @@ -99,22 +99,21 @@ namespace MapControl images[1] is WriteableBitmap image2 && image1.PixelHeight == image2.PixelHeight) { - var width = image1.PixelWidth + image2.PixelWidth; - var height = image2.PixelHeight; - var stride1 = image1.PixelWidth * 4; - var stride2 = image2.PixelWidth * 4; - var buffer1 = image1.PixelBuffer.ToArray(); - var buffer2 = image2.PixelBuffer.ToArray(); + var buffer1 = image1.PixelBuffer; + var buffer2 = image2.PixelBuffer; + var stride1 = (uint)image1.PixelWidth * 4; + var stride2 = (uint)image2.PixelWidth * 4; + var stride = stride1 + stride2; + var height = image1.PixelHeight; - image = new WriteableBitmap(width, height); + image = new WriteableBitmap(image1.PixelWidth + image2.PixelWidth, height); - using (var pixelStream = image.PixelBuffer.AsStream()) + var buffer = image.PixelBuffer; + + for (uint y = 0; y < height; y++) { - for (var y = 0; y < height; y++) - { - await pixelStream.WriteAsync(buffer1, y * stride1, stride1); - await pixelStream.WriteAsync(buffer2, y * stride2, stride2); - } + buffer1.CopyTo(y * stride1, buffer, y * stride, stride1); + buffer2.CopyTo(y * stride2, buffer, y * stride + stride1, stride2); } }