gpt4 book ai didi

c# - WPF:截图并保存

转载 作者:太空狗 更新时间:2023-10-29 22:30:25 25 4
gpt4 key购买 nike

<分区>

我是 WPF 应用程序的新手,我试着环顾四周,看看是否能找到适用于此的东西,但到目前为止我还没有找到任何有用的东西(我猜这是因为大部分已经过时了)。我想截取整个桌面(即所有显示器)的屏幕截图,并在单击屏幕截图按钮时将其作为 .jpg 保存到特定文件夹,并将时间和日期作为文件名。我能够在我的 Windows 窗体应用程序中实现这一点,但无法在我的 WPF 应用程序中实现。

这是我用于我的 Windows 窗体应用程序的代码。

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

using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
{
using (Graphics g = Graphics.FromImage(bmp))
{
String filename = "ScreenCapture-" + DateTime.Now.ToString("ddMMyyyy-hhmmss") + ".png";
Opacity = .0;
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
bmp.Save("C:\\ScreenShots\\" + filename);
Opacity = 1;
}
}

如有任何帮助,我们将不胜感激。

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