private void btn_openFile_Click(object sender, EventArgs e) { //open a file for import var fileContent = string.Empty; var filePath = string.Empty; Image currentImage; pic_modifiedImage.Image = null; rTxt_imageMsg.Text = string.Empty; using (OpenFileDialog fileDialog = new OpenFileDialog()) { fileDialog.InitialDirectory = "c:\\"; fileDialog.Filter = "Image Files (*.jpg)|*.jpg | All files (*.*)|*.*"; fileDialog.FilterIndex = 2; fileDialog.RestoreDirectory = true; if (fileDialog.ShowDialog() == DialogResult.OK) { try { filePath = fileDialog.FileName; txtBx_filePath.Text = filePath; using (var bmpStream = System.IO.File.Open(filePath, System.IO.FileMode.Open)) { currentImage = Image.FromStream(bmpStream); var currentImageBitMap = new Bitmap(currentImage); pic_orgImage.Image = currentImage; sBitMap = new stag_Bitmap(currentImageBitMap, numBitsUse); } if (sBitMap.TestForMessage()) { var confirmResult = MessageBox.Show("A message has been detected in the image that was opened.", "Would you like to try and decode the message?", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { startDecodeAsync(currentImage); } } pnl_msg.Visible = true; lbl_maxMsgSizeVal.Text = sBitMap.MaxMsgSize.ToString(); } catch (Exception ex) { MessageBox msgBox; string message = "An error occurred while opening the file: " + ex.Message; MessageBox.Show(message); } } } }
private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Save Location"; saveFileDialog.CheckPathExists = true; saveFileDialog.RestoreDirectory = true; saveFileDialog.Filter = "Image Files (*.bmp)|*.bmp"; if (pic_modifiedImage.Image != null) { if (saveFileDialog.ShowDialog() == DialogResult.OK) { var name = saveFileDialog.FileName; stag_Bitmap testMap = new stag_Bitmap(sBitMap.newBitmap); testMap.TestForMessage(); sBitMap.newBitmap.Save(name, ImageFormat.Bmp); } } else { //show alert that there is no file to save } }