//-------------------------------------------------------------------------------------- // SaveFunction: The saving function when an image already has a save location. //-------------------------------------------------------------------------------------- private void SaveFunction() { // Get the current tabview TabView tabview = ((TabView)tabControl1.SelectedTab.Controls[0]); // Check if something has a file path or not //if it already does then dont use save dialog and just go ahead and save the file if (tabview.GetNewFile() == false) { if (tabview.GetDirectory() != null) { // Get image and save image to save location. Image image = tabview.GetImage(); image.Save(tabview.GetDirectory()); tabview.SetAltered(false); tabview.SetNewFile(false); } } // The file hasnt been saved before, need thesave dialog else if (tabview.GetNewFile() == true) { SaveAsFunction(); } }
//-------------------------------------------------------------------------------------- // SaveAsFunction: The saving function when an image doesnt have a saved file. //-------------------------------------------------------------------------------------- private void SaveAsFunction() { // New save dialog SaveFileDialog save = new SaveFileDialog(); // Filter which files can be saved. save.Filter = "PNG|*.png|BMP|*.bmp|GIF|*.gif|JPG|*.jpg|JPEG|*.jpeg|TIF|*.tif|TIFF|*.tiff"; // Set image format ImageFormat format = ImageFormat.Png; // Show dialog box. if (save.ShowDialog() == DialogResult.OK) { //get filename extensions. string ext = System.IO.Path.GetExtension(save.FileName); switch (ext) { // png. case ".png": format = ImageFormat.Png; break; // bmp. case ".bmp": format = ImageFormat.Bmp; break; // gif. case ".gif": format = ImageFormat.Gif; break; // jpg. case ".jpg": format = ImageFormat.Jpeg; break; // jpeg. case ".jpeg": format = ImageFormat.Jpeg; break; // tif. case ".tif": format = ImageFormat.Tiff; break; // tiff. case ".tiff": format = ImageFormat.Tiff; break; } // Get the current tabview TabView tabview = ((TabView)tabControl1.SelectedTab.Controls[0]); // Get image and save image to save location. Image image = tabview.GetImage(); image.Save(save.FileName, format); // Set altered and new to false tabview.SetAltered(false); tabview.SetNewFile(false); tabview.SetDirectory(save.FileName); // Set the tab name tabControl1.SelectedTab.Text = System.IO.Path.GetFileName(save.FileName); } }