gpt4 book ai didi

C# 全屏截图

转载 作者:行者123 更新时间:2023-12-05 01:41:33 25 4
gpt4 key购买 nike

我正在尝试使用 .NET Framework 编写控制台应用程序。我想截图我的屏幕。我在这样的 SO 上使用了其他答案:

https://stackoverflow.com/a/24879511/9457997

问题是这并没有捕获我的整个屏幕。它在底部和右侧缺失了大约 1/5。

如何使用 C# .NET Framework 捕获我的整个屏幕?

最佳答案

使用VirtualScreen :

int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;

// Create a bitmap of the appropriate size to receive the full-screen screenshot.
using (Bitmap bitmap = new Bitmap(screenWidth, screenHeight))
{
// Draw the screenshot into our bitmap.
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bitmap.Size);
}

//Save the screenshot as a Jpg image
var uniqueFileName = "C:\\temp\\a.Jpg";
try
{
bitmap.Save(uniqueFileName, ImageFormat.Jpeg);
}
catch (Exception ex) {
}
}

关于C# 全屏截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54174052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com