diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0379056..fee80a8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support `tiff` files for icon.
### Updated
- Update `GetBitmapFrame` to round `width` that is changed by `dpi`.
-- Add `GetBitmapFrameByDpiAndWidth` to get optimal frame by `dpi` and `width`.
+- Add `GetBitmapFrameByWidthAndDpi` to get optimal frame by `dpi` and `width`.
+- Add `GetSystemDpi` to get the system `dpi` on the fly.
### Example
- Add `Cube-Grey-Light.tiff` and `Cube-Grey-Dark.tiff` in `AppTheme`.
diff --git a/ricaun.Revit.UI/BitmapExtension.cs b/ricaun.Revit.UI/BitmapExtension.cs
index d85500f..55f5656 100644
--- a/ricaun.Revit.UI/BitmapExtension.cs
+++ b/ricaun.Revit.UI/BitmapExtension.cs
@@ -83,19 +83,28 @@ public static ImageSource Scale(this ImageSource imageSource, double scale)
}
///
- /// Get the bitmap frame from the based on the DPI and width.
+ /// Get the system DPI based on the using a new .
///
- /// The bitmap decoder.
- /// The desired width of the bitmap frame. When set to zero, the smallest width frame is returned.
- /// The bitmap frame with the specified width or the smallest width frame.
- internal static BitmapFrame GetBitmapFrameByDpiAndWidth(this BitmapDecoder bitmapDecoder, int width = 0)
+ internal static double GetSystemDpi()
{
double systemDpi = 96;
-
#if NET47_OR_GREATER || NET
var imageScaleInfo = VisualTreeHelper.GetDpi(new System.Windows.Controls.Image());
systemDpi = imageScaleInfo.PixelsPerInchX;
#endif
+ return systemDpi;
+ }
+
+ ///
+ /// Get the bitmap frame from the based on the DPI and width.
+ ///
+ /// The bitmap decoder.
+ /// The desired width of the bitmap frame. When set to zero, the smallest width frame is returned.
+ /// The optimal dpi for the frame.
+ /// The bitmap frame with the specified width or the smallest width frame.
+ internal static BitmapFrame GetBitmapFrameByWidthAndDpi(this BitmapDecoder bitmapDecoder, int width = 0, int dpi = 0)
+ {
+ double systemDpi = dpi > 0 ? dpi : GetSystemDpi();
var frames = bitmapDecoder.Frames;
var frame = frames
@@ -134,7 +143,7 @@ TImageSource ScaleDownIfWidthIsGreater(TImageSource imageSource, int width)
{
bitmapFrame.DownloadCompleted += (s, e) =>
{
- if (bitmapFrame.Decoder.GetBitmapFrameByDpiAndWidth(width) is TImageSource frame)
+ if (bitmapFrame.Decoder.GetBitmapFrameByWidthAndDpi(width) is TImageSource frame)
imageSource = frame;
imageSource = ScaleDownIfWidthIsGreater(imageSource, width);
@@ -143,7 +152,7 @@ TImageSource ScaleDownIfWidthIsGreater(TImageSource imageSource, int width)
};
}
- if (bitmapFrame.Decoder.GetBitmapFrameByDpiAndWidth(width) is TImageSource frame)
+ if (bitmapFrame.Decoder.GetBitmapFrameByWidthAndDpi(width) is TImageSource frame)
imageSource = frame;
}