Skip to content

Commit a80eb05

Browse files
authored
Change DPI to 96 (#1781)
1 parent 37cd51b commit a80eb05

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/Magick.NET.AvaloniaMediaImaging/IMagickImageExtentions.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,34 @@ namespace ImageMagick;
1515
public static partial class IMagickImageExtentions
1616
{
1717
/// <summary>
18-
/// Converts this instance to a <see cref="WriteableBitmap"/>.
18+
/// Converts this instance to a <see cref="WriteableBitmap"/> with a default DPI of 96x96.
1919
/// </summary>
2020
/// <param name="self">The image.</param>
2121
/// <typeparam name="TQuantumType">The quantum type.</typeparam>
2222
/// <returns>A <see cref="WriteableBitmap"/>.</returns>
2323
public static unsafe WriteableBitmap ToWriteableBitmap<TQuantumType>(this IMagickImage<TQuantumType> self)
2424
where TQuantumType : struct, IConvertible
25+
{
26+
return self.ToWriteableBitmapInternal(false);
27+
}
28+
29+
/// <summary>
30+
/// Converts this instance to a <see cref="WriteableBitmap"/>.
31+
/// </summary>
32+
/// <param name="self">The image.</param>
33+
/// <typeparam name="TQuantumType">The quantum type.</typeparam>
34+
/// <returns>A <see cref="WriteableBitmap"/>.</returns>
35+
public static unsafe WriteableBitmap ToWriteableBitmapWithDensity<TQuantumType>(this IMagickImage<TQuantumType> self)
36+
where TQuantumType : struct, IConvertible
37+
{
38+
return self.ToWriteableBitmapInternal(true);
39+
}
40+
41+
private static unsafe WriteableBitmap ToWriteableBitmapInternal<TQuantumType>(this IMagickImage<TQuantumType> self, bool withDensity)
42+
where TQuantumType : struct, IConvertible
2543
{
2644
var size = new PixelSize((int)self.Width, (int)self.Height);
27-
var density = new Vector(self.Density.X, self.Density.Y);
45+
var density = withDensity ? new Vector(self.Density.X, self.Density.Y) : new Vector(96, 96);
2846
var bitmap = new WriteableBitmap(size, density, PixelFormats.Rgba8888, AlphaFormat.Unpremul);
2947

3048
using var framebuffer = bitmap.Lock();

0 commit comments

Comments
 (0)