예제 #1
0
        public static double ConvertSizeRectDpiToSystemDpi(Rect rect, double size)
        {
            Dpi systemDpi = GetSystemDpi();
            Dpi rectDpi   = DpiChecker.GetDpiFromRect(rect);

            return(size * systemDpi.X / rectDpi.X);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        public static double GetAbsoluteScaleFactorFromRect(Rect rect)
        {
            double scaleFactor = (double)DpiChecker.GetDpiFromRect(rect).X / (double)Dpi.Default.X;

            return(scaleFactor);
        }