public static double ConvertSizeRectDpiToSystemDpi(Rect rect, double size) { Dpi systemDpi = GetSystemDpi(); Dpi rectDpi = DpiChecker.GetDpiFromRect(rect); return(size * systemDpi.X / rectDpi.X); }
/// <summary> /// Gets a ScaleTransform used to manually scale elements to be the correct size on monitors with non-system DPI. The Rect passed in is used to find the monitor DPI that the rect is on. The Rect should be the WPF System-DPI coordinates. /// </summary> /// <param name="rect">WPF System-DPI coordinates</param> /// <returns>ScaleTransform with a scale factor that is Monitor DPI / System DPI</returns> public static ScaleTransform GetScaleTransformForRect(Rect rect) { double monitorScaleFactorX = (double)DpiChecker.GetDpiFromRect(rect).X / (double)DpiUtil.GetSystemDpi().X; double monitorScaleFactorY = (double)DpiChecker.GetDpiFromRect(rect).Y / (double)DpiUtil.GetSystemDpi().Y; ScaleTransform scaleTransform = new ScaleTransform(monitorScaleFactorX, monitorScaleFactorY); return(scaleTransform); }
public static double GetAbsoluteScaleFactorFromRect(Rect rect) { double scaleFactor = (double)DpiChecker.GetDpiFromRect(rect).X / (double)Dpi.Default.X; return(scaleFactor); }