private async Task startEmbedAsync() { var currentImageBitMap = new Bitmap(pic_orgImage.Image); sBitMap = new stag_Bitmap(currentImageBitMap, numBitsUse); sBitMap.Message = rTxt_imageMsg.Text; Debug.WriteLine("Beginning Encode"); await Task.Run(sBitMap.embedMessageAsync); rTxt_imageMsg.Enabled = true; Debug.WriteLine("Displaying modified image"); pic_modifiedImage.Image = sBitMap.newBitmap; }
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); } } } }
//decode the message contained in the message and set the message to the message box private async Task startDecodeAsync(Image image) { Bitmap modifiedBitmap = new Bitmap(image); stag_Bitmap decodeTest = new stag_Bitmap(modifiedBitmap); try { await Task.Run(decodeTest.decodeMessageAsync); rTxt_imageMsg.Text = decodeTest.Message; }catch (Exception ex) { Debug.WriteLine(ex.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 } }