public Bitmap Encode(Bitmap inputImage, IInputMessage inputMessage) { Bitmap image = new Bitmap(inputImage); const int lastBit = 0; // index of current bit of inputMessage int bitIndex = 0; string messageWithHeader = inputMessage.GetMessageWithHeader(); int messageLength = messageWithHeader.Length; for (int i = 0; i < image.Height; i++) { for (int j = 0; j < image.Width; j++) { Color pixel = image.GetPixel(j, i); int R = pixel.R; int G = pixel.G; int B = pixel.B; // pass through every channel for (int n = 0; n < 3; n++) { if (bitIndex == messageLength) { Color newPixel = Color.FromArgb(R, G, B); image.SetPixel(j, i, newPixel); return(image); } switch (n) { case 0: { R ^= (-messageWithHeader[bitIndex] ^ R) & (1 << lastBit); bitIndex++; break; } case 1: { G ^= (-messageWithHeader[bitIndex] ^ G) & (1 << lastBit); bitIndex++; break; } case 2: { B ^= (-messageWithHeader[bitIndex] ^ B) & (1 << lastBit); bitIndex++; Color newPixel = Color.FromArgb(R, G, B); image.SetPixel(j, i, newPixel); break; } } } } } return(image); }
public Bitmap Encode(Bitmap inputImage, IInputMessage inputMessage) { Bitmap image = new Bitmap(inputImage); Dictionary <int, int> histogram = calculateHistogram(image); Tuple <int, int, int, int> myTuple = findMinAndMax(histogram); int min = myTuple.Item1; int max = myTuple.Item2; int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; /* Console.WriteLine("Max value is: " + max + " for index: " + maxIndex); * Console.WriteLine("Min value is: " + min + " for index: " + minIndex);*/ string messageWithHeader = inputMessage.GetMessageWithHeader(); if (maxIndex < minIndex) { shiftHistogramRight(image, minIndex, maxIndex); encodeMessageRight(image, messageWithHeader, minIndex, maxIndex); } else if (maxIndex > minIndex) { shiftHistogramLeft(image, minIndex, maxIndex); encodeMessageLeft(image, messageWithHeader, minIndex, maxIndex); } return(image); }