🐛 修复缩放屏幕截图bug

This commit is contained in:
BookerLiu
2022-07-27 17:13:45 +08:00
parent a682f27223
commit 43314a3006
3 changed files with 40 additions and 23 deletions

View File

@@ -120,5 +120,30 @@ namespace GeekDesk.Util
return screenPixel.GetPixel(0, 0);
}
[DllImport("gdi32")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
public const int HORZRES = 8;
public const int VERTRES = 10;
public const int DESKTOPVERTRES = 117;
public const int DESKTOPHORZRES = 118;
/// <summary>
/// 获取屏幕缩放比例
/// </summary>
/// <returns></returns>
public static double GetScreenScalingFactor()
{
var g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
var physicalScreenHeight = GetDeviceCaps(desktop, (int)DESKTOPVERTRES);
var screenScalingFactor =
(double)physicalScreenHeight / SystemParameters.PrimaryScreenHeight;
//SystemParameters.PrimaryScreenHeight;
return screenScalingFactor;
}
}
}