ImageLoader

This commit is contained in:
ClemensFischer 2025-01-01 19:45:40 +01:00
parent 560f44a139
commit 069072ce34
6 changed files with 73 additions and 71 deletions

View file

@ -42,22 +42,22 @@ namespace MapControl
internal static async Task<IImage> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
{
WriteableBitmap mergedImage = null;
WriteableBitmap mergedBitmap = null;
var images = await LoadImagesAsync(uri1, uri2, progress);
if (images.Length == 2 &&
images[0] is Bitmap image1 &&
images[1] is Bitmap image2 &&
image1.PixelSize.Height == image2.PixelSize.Height &&
image1.Format.HasValue &&
image1.Format == image2.Format &&
image1.AlphaFormat.HasValue &&
image1.AlphaFormat == image2.AlphaFormat)
images[0] is Bitmap bitmap1 &&
images[1] is Bitmap bitmap2 &&
bitmap1.PixelSize.Height == bitmap2.PixelSize.Height &&
bitmap1.Format.HasValue &&
bitmap1.Format == bitmap2.Format &&
bitmap1.AlphaFormat.HasValue &&
bitmap1.AlphaFormat == bitmap2.AlphaFormat)
{
var bpp = image1.Format.Value == PixelFormat.Rgb565 ? 2 : 4;
var pixelSize = new PixelSize(image1.PixelSize.Width + image2.PixelSize.Width, image1.PixelSize.Height);
var stride1 = bpp * image1.PixelSize.Width;
var bpp = bitmap1.Format.Value == PixelFormat.Rgb565 ? 2 : 4;
var pixelSize = new PixelSize(bitmap1.PixelSize.Width + bitmap2.PixelSize.Width, bitmap1.PixelSize.Height);
var stride1 = bpp * bitmap1.PixelSize.Width;
var stride = bpp * pixelSize.Width;
var bufferSize = stride * pixelSize.Height;
@ -67,15 +67,15 @@ namespace MapControl
{
var buffer = (nint)ptr;
image1.CopyPixels(new PixelRect(image1.PixelSize), buffer, bufferSize, stride);
image2.CopyPixels(new PixelRect(image2.PixelSize), buffer + stride1, bufferSize, stride);
bitmap1.CopyPixels(new PixelRect(bitmap1.PixelSize), buffer, bufferSize, stride);
bitmap2.CopyPixels(new PixelRect(bitmap2.PixelSize), buffer + stride1, bufferSize, stride);
mergedImage = new WriteableBitmap(image1.Format.Value, image1.AlphaFormat.Value, buffer, pixelSize, image1.Dpi, stride);
mergedBitmap = new WriteableBitmap(bitmap1.Format.Value, bitmap1.AlphaFormat.Value, buffer, pixelSize, bitmap1.Dpi, stride);
}
}
}
return mergedImage;
return mergedBitmap;
}
}
}