示例#1
0
        private Color embedTextMessage(byte[] messageData, Color sourcePixelColor, int currentIndex, int bpcc)
        {
            var pixelInfo         = ColorByteArrayConverter.GetByteArray(sourcePixelColor);
            var count             = 0;
            var embeddedPixelInfo = new byte[PixelConstants.NumberOfColorChannels];

            foreach (var colorInfo in pixelInfo)
            {
                var currColor = colorInfo;
                currColor >>= bpcc;
                currColor <<= bpcc;

                var bitsToAdd = new BitArray(this.numberOfBitsInByte);
                for (var j = 0; j < bpcc; j++)
                {
                    if (currentIndex + j < messageData.Length * this.numberOfBitsInByte)
                    {
                        var currentByte = messageData[this.currentByteIndex];
                        var currentBit  = isBitSet(currentByte, currentIndex % 8);
                        bitsToAdd.Set(j, currentBit);

                        if (currentIndex != 0 && (currentIndex + j) % this.numberOfBitsInByte == 0)
                        {
                            this.currentByteIndex++;
                        }
                    }
                    else
                    {
                        bitsToAdd.Set(j, false);
                    }
                }

                var bitsAsByte = new byte[1];
                bitsToAdd.CopyTo(bitsAsByte, 0);

                currColor |= bitsAsByte[0];
                embeddedPixelInfo[count] = currColor;

                currentIndex += bpcc;
                count++;
            }

            return(Color.FromArgb(0, embeddedPixelInfo[0], embeddedPixelInfo[1], embeddedPixelInfo[2]));
        }
示例#2
0
        private void extractMessageBitsFromPixel(Color embeddedPixelColor, int count)
        {
            var colorInfo = ColorByteArrayConverter.GetByteArray(embeddedPixelColor);

            foreach (var color in colorInfo)
            {
                var currColor = color;

                var colorByte = new[] { currColor };
                var colorBits = new BitArray(colorByte);

                for (var j = 0; j < this.bpcc; j++)
                {
                    this.embeddedBits.Set(count, colorBits.Get(j));
                    this.handleExtractLetter(count);
                    count++;
                }
            }
        }