我正在使用此问题中的代码,将屏幕截图保存到位图中: Capture the Screen into a Bitmap
有一个问题,行Screen.PrimaryScreen.Bounds.X
和Screen.PrimaryScreen.Bounds.Y
返回1500,1000
,但我的屏幕是3000,2000
,缩放比例为200%
此错误的结果是从左上角起尺寸为1500,1000的图像。
我的解决方法是将尺寸乘以2,但是我不想对比例因子进行硬编码,我想以某种方式单独获得它。
我也尝试过此操作,但是此注册表项在我的计算机上根本不存在: Get scale of screen
here the 2 screenshots, 1. what i want 2. what i get
我当前的代码:
int boundsX = Screen.PrimaryScreen.Bounds.X * 2;
int boundsY = Screen.PrimaryScreen.Bounds.Y * 2;
Size screenSize = Screen.PrimaryScreen.Bounds.Size;
screenSize = new Size(screenSize.Width * 2, screenSize.Height * 2);
int boundsWidth = Screen.PrimaryScreen.Bounds.Width * 2;
int boundsHeight = Screen.PrimaryScreen.Bounds.Height * 2;
// Create a new bitmap.
var bmpScreenshot = new Bitmap(boundsWidth,
boundsHeight,
PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(boundsX,
boundsY,
0,
0,
screenSize ,
CopyPixelOperation.SourceCopy);
bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);