private void cleanButton_Click(object sender, RoutedEventArgs e) { Bitmap image = null; if (algorithmsComboBox.SelectedItem.ToString() == "LSB") { // LSB is not reversible - do nothing } else if (algorithmsComboBox.SelectedItem.ToString() == "Histogram shifting") { HSSettings tab = settingsTabControl.SelectedContent as HSSettings; int minIndex = tab.getMinIndex(); int maxIndex = tab.getMaxIndex(); image = HS.Instance.Clean(new Bitmap(carrierViewer.filename), minIndex, maxIndex); } ImageFormat format = ImageFormat.Png; SaveFileDialog sfd = new SaveFileDialog(); string ext = System.IO.Path.GetExtension(carrierViewer.filename); switch (ext) { case ".png": sfd.Filter = "Save Format|*.png"; format = ImageFormat.Png; break; case ".jpg": sfd.Filter = "Save Format|*.jpg"; format = ImageFormat.Jpeg; break; case ".bmp": sfd.Filter = "Save Format|*.bmp"; format = ImageFormat.Bmp; break; } if (sfd.ShowDialog() == true) { image.Save(sfd.FileName); } }
private void decryptButton_Click(object sender, RoutedEventArgs e) { string message = null; int imageHeight = 0; int imageWidth = 0; Bitmap drawnImage = null; MessageType messageType = MessageType.Plaintext; if (algorithmsComboBox.SelectedItem.ToString() == "LSB") { IOutputMessage messageInBits = LSB.Instance.Decode(new Bitmap(carrierViewer.filename)); messageType = messageInBits.GetHeaderData().GetMessageType(); string outputMessage = messageInBits.GetContent(); switch (messageType) { case MessageType.Plaintext: message = AlgorithmUtility.bitMessageToText(outputMessage, (int)LSBHeaderConstants.PlainTextHeaderLength); break; case MessageType.BinaryImage: message = outputMessage.Substring((int)LSBHeaderConstants.BinaryImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawBinaryImage(message, imageWidth, imageHeight); break; case MessageType.GrayscaleImage: message = outputMessage.Substring((int)LSBHeaderConstants.GrayscaleImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawGrayscaleImage(message, imageWidth, imageHeight); break; case MessageType.ColorImage: message = outputMessage.Substring((int)LSBHeaderConstants.ColorImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawColorImage(message, imageWidth, imageHeight); break; } } else if (algorithmsComboBox.SelectedItem.ToString() == "Histogram shifting") { HSSettings tab = settingsTabControl.SelectedContent as HSSettings; int minIndex = tab.getMinIndex(); int maxIndex = tab.getMaxIndex(); IOutputMessage messageInBits = HS.Instance.Decode(new Bitmap(carrierViewer.filename), minIndex, maxIndex); messageType = messageInBits.GetHeaderData().GetMessageType(); string outputMessage = messageInBits.GetContent(); switch (messageType) { case MessageType.Plaintext: message = AlgorithmUtility.bitMessageToText(outputMessage, (int)HSHeaderConstants.PlainTextHeaderLength); break; case MessageType.BinaryImage: message = outputMessage.Substring((int)HSHeaderConstants.BinaryImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawBinaryImage(message, imageWidth, imageHeight); break; case MessageType.GrayscaleImage: message = outputMessage.Substring((int)HSHeaderConstants.GrayscaleImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawGrayscaleImage(message, imageWidth, imageHeight); break; case MessageType.ColorImage: message = outputMessage.Substring((int)HSHeaderConstants.ColorImageHeaderLength); imageHeight = messageInBits.GetHeaderData().GetImageHeight(); imageWidth = messageInBits.GetHeaderData().GetImageWidth(); drawnImage = ImageDrawer.Instance.DrawColorImage(message, imageWidth, imageHeight); break; } } // need to change this dynamically if (messageType == MessageType.Plaintext) { messageTabControl.SelectedItem = messageTextBox; TextBox tab = messageTabControl.SelectedContent as TextBox; tab.Text = message; //messageTextBox.selec = message; } else { messageTabControl.SelectedItem = messageImage; Image tab = messageTabControl.SelectedContent as Image; tab.Source = ToBitmapImage(drawnImage); } }