public void Save(string filePath, string fileName, bool includeDateTime, string fileNameSuffix) { if (Bitmap == null) { return; // TODO: throw exception? } filePath = FileHelper.ExpandPath(mProject, filePath); if (!filePath.EndsWith("\\")) { filePath += "\\"; } if (!Directory.Exists(filePath)) { try { Directory.CreateDirectory(filePath); } catch (Exception e) { throw new ArgumentException("Unable to save image to '" + filePath + "'. Reason=Unable to create directory. Low-level message=" + e.Message); } } filePath += fileName; if (includeDateTime) { filePath += "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); } filePath += fileNameSuffix; if (Bitmap.RawFormat.Equals(ImageFormat.Bmp)) { filePath += ".bmp"; } else if (Bitmap.RawFormat.Equals(ImageFormat.MemoryBmp)) { filePath += ".jpg"; //TODO: is this right? it's coming from camera, so it should be jpg. } else if (Bitmap.RawFormat.Equals(ImageFormat.Jpeg)) { filePath += ".jpg"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Png)) { filePath += ".png"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Gif)) { filePath += ".gif"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Emf)) { filePath += ".emf"; } else if (Bitmap.RawFormat.Equals(ImageFormat.MemoryBmp)) { filePath += "ZZZ.bmp"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Exif)) { filePath += "ZZZ.jpg"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Tiff)) { filePath += ".tif"; } else if (Bitmap.RawFormat.Equals(ImageFormat.Wmf)) { filePath += ".wmf"; } else { mProject.LogError("Can't save image. Unsupported file type. Type=" + Bitmap.RawFormat.ToString()); filePath += ".jpg"; //hack } try { Bitmap.Save(filePath); } catch (Exception e) { throw new ArgumentException("Unable to save image to '" + filePath + "'. Low-level message=" + e.Message); } }