现在我有这个代码:
int number = 0;
DirectoryInfo di = new DirectoryInfo(scpath + @"Screenshots\");
if (di.Exists) {
} else {
di.Create();
}
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save(di + "Screenshot_" + number, ImageFormat.Jpeg);
程序截取屏幕截图(有效)并保存。我想要做的是让程序检查并查看屏幕截图是否存在(“Screenshot_*”),如果不存在则创建它。如果是这样,请递增文件名,直到它达到“屏幕截图_”末尾未使用的数字。鉴于文件和递增更多,不确定如何处理。我正在考虑一个 for 循环,但我现在正在玩它。