public string ExtractMessage()
        {
            var bitsOutput    = "";
            var counter       = 0;
            var bitTextParser = new BitTextParser();
            var bitsDelimiter = bitTextParser.TextToBits(delimiter);
            var widthRange    = range(Image.Width);
            var heigthRange   = range(Image.Height);

            try
            {
                foreach (int w in widthRange)
                {
                    foreach (int h in heigthRange)
                    {
                        if (w % 2 == 0 && h % 2 == 0)
                        {
                            bitsOutput += (Image.GetPixel(w, h).R & 1).ToString();
                            if (++counter % 8 == 0 && bitsOutput.EndsWith(bitsDelimiter))
                            {
                                throw new Exception("delimter reached");
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(bitTextParser.BitsToText(bitsOutput.Remove(bitsOutput.Length - 8)));
        }
Beispiel #2
0
        public void InsertMessage(string message, string outputImgPath)
        {
            int counter = 0;

            var bits             = new BitTextParser().TextToBits(message + delimiter);
            var watermarkedColor = new WatermarkedColor();
            var widthRange       = range(Image.Width);
            var heigthRange      = range(Image.Height);

            foreach (int w in widthRange)
            {
                foreach (int h in heigthRange)
                {
                    if (w % 2 == 0 && h % 2 == 0 && counter < bits.Length)
                    {
                        var oldPixel = Image.GetPixel(w, h);
                        var newPixel = watermarkedColor.getWaterMarked(
                            bits[counter++], oldPixel);

                        Image.SetPixel(w, h, newPixel);
                    }
                }
            }

            Image.Save(outputImgPath);
        }