尝试制作一个程序,该程序将获取我的监视器屏幕的屏幕截图,并将其保存到我将使用按钮查看的特定路径,请参见Button1_Click。然后,我将其保存到属性设置中,并在每次程序启动时加载它,但是即使在TakeScreenshotBtn_Click中bmpScreen.Save所在的位置,我似乎也无法将其保存到特定路径。要么将其保存到.exe运行的位置 否则它什么也不会做。我使用了@ label2.text。它会引发GDI +错误。
捕获屏幕:
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
LogTxtBox.AppendText("[#] Captured whole monitor." + Environment.NewLine);
await Task.Delay(1000);
label2.Text = Properties.Settings.Default.SavingPath.ToString();
bmpScreenshot.Save(label2.Text + "Capture-" + DateTime.Now.ToString("yyyy-MM-dd-h-mm-tt") + ".png", ImageFormat.Png);
LogTxtBox.AppendText("[#] Saved screenshot under name : " + DateTime.Now.ToString("yyyy-MM-dd-h-mm-tt") + Environment.NewLine);
设置路径:
DialogResult result = SetFolderPath.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(SetFolderPath.SelectedPath)) {
string Path = SetFolderPath.SelectedPath;
ClickNShare.Properties.Settings.Default.SavingPath = Path;
ClickNShare.Properties.Settings.Default.Save();
MessageBox.Show("Path set to: " + Path.ToString(), "Path set!", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogTxtBox.AppendText("[#] Path set to: " + Path.ToString() + Environment.NewLine);
}