private void saveImage_Click(object sender, EventArgs e) { if (currentImageTransformed == null) { MessageBox.Show("You must load an image."); return; } saveFileDialog.FileName = openedFileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { C2PFile c2pFile = new C2PFile(currentImageTransformed); try { using (BinaryWriter bw = new BinaryWriter(new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate, FileAccess.Write))) { bw.Write(c2pFile.FileData); } } catch (IOException ex) { MessageBox.Show(String.Format("Could not save file.\n\nException: {0}", ex)); } } }