diff --git a/src/Magick.NET.AvaloniaMediaImaging/IMagickImageExtentions.cs b/src/Magick.NET.AvaloniaMediaImaging/IMagickImageExtentions.cs index b83e0cabaa..8e82290583 100644 --- a/src/Magick.NET.AvaloniaMediaImaging/IMagickImageExtentions.cs +++ b/src/Magick.NET.AvaloniaMediaImaging/IMagickImageExtentions.cs @@ -15,16 +15,34 @@ namespace ImageMagick; public static partial class IMagickImageExtentions { /// - /// Converts this instance to a . + /// Converts this instance to a with a default DPI of 96x96. /// /// The image. /// The quantum type. /// A . public static unsafe WriteableBitmap ToWriteableBitmap(this IMagickImage self) where TQuantumType : struct, IConvertible + { + return self.ToWriteableBitmapInternal(false); + } + + /// + /// Converts this instance to a . + /// + /// The image. + /// The quantum type. + /// A . + public static unsafe WriteableBitmap ToWriteableBitmapWithDensity(this IMagickImage self) + where TQuantumType : struct, IConvertible + { + return self.ToWriteableBitmapInternal(true); + } + + private static unsafe WriteableBitmap ToWriteableBitmapInternal(this IMagickImage self, bool withDensity) + where TQuantumType : struct, IConvertible { var size = new PixelSize((int)self.Width, (int)self.Height); - var density = new Vector(self.Density.X, self.Density.Y); + var density = withDensity ? new Vector(self.Density.X, self.Density.Y) : new Vector(96, 96); var bitmap = new WriteableBitmap(size, density, PixelFormats.Rgba8888, AlphaFormat.Unpremul); using var framebuffer = bitmap.Lock();