1. Automatically save photos: specify the path to save the C drive to save:
String savePath = @"C:\";
string filename = $"{DateTime.Now:yyyyMMddHHmmss}.jpg";
string filepath = savePath + filename;
// take a picture and save the image
Bitmap image = TakePhoto();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
2. Automatically save photos: under the current running directory:
string filename = $"{DateTime.Now:yyyyMMddHHmmss}.jpg";
string filepath = Path.Combine(Environment.CurrentDirectory, filename);
// take a picture and save the image
Bitmap image = TakePhoto();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
3. Automatically save photos: Desktop:
string filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"{DateTime.Now:yyyyMMddHHmmss}.jpg");
// take a picture and save the image
Bitmap image = TakePhoto();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
4. Manually save photos: choose a path to save
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.FileName = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg";
// Selected file path
string filepath= saveFileDialog1.FileName.ToString();
// take a picture and save the image
Bitmap image = TakePhoto();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
5. Automatically save photos: the current program runs under the new directory temp
string tmpdir = System.IO.Path.Combine(Application.StartupPath, "temp");
if (!System.IO.Directory.Exists(tmpdir))
{
System.IO.Directory.CreateDirectory(tmpdir);
}
string filename = $"{DateTime.Now:yyyyMMddHHmmss}.jpg";
string filepath = System.IO.Path.Combine( tmpdir ,filename);
// take a picture and save the image
Bitmap image = TakePhoto();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);