我正在尝试将屏幕截图保存到位于应用程序基目录内的img
子目录中;但是,图像文件保存在应用程序基目录中。我应该怎么做才能将图像保存到img
子目录中?
法典:
private void screenCapture()
{
try
{
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string pathString = System.IO.Path.Combine(appDir, "img");
Bitmap memoryImage;
memoryImage = new Bitmap(1000, 900);
Size s = new Size(memoryImage.Width, memoryImage.Height);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
string fileName =
string.Format(pathString
+ DateTime.Now.ToString("yyyyMMdd_hhmmss")
+ ".png");
// save it
memoryImage.Save(fileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
您只是没有正确组合路径组件和文件名。试试这个:
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string pathString = System.IO.Path.Combine(appDir, "img");
string fileName = DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".png";
string fullPath = System.IO.Path.Combine(pathString, fileName);