示例#1
0
        /// <summary>
        ///     Embeds the monochrome image in the source bitmap image by
        ///     using the least significant bit to alter the color.
        ///     Precondition: bitmap is not null, bitmap is not larger than source
        ///     Post-condition: least significant bit in the source image is replaced.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="encrypt">Whether or not to encrypt the image.</param>
        /// <exception cref="ArgumentNullException">bitmap</exception>
        /// <exception cref="SecretTooLargeException">bitmap is too big to fit</exception>
        public void EmbedMonochromeImage(MonochromeBitmap bitmap, bool encrypt)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException(nameof(bitmap));
            }
            if (bitmap.Width > this.Width || bitmap.Height > this.Height)
            {
                throw new SecretTooLargeException();
            }

            for (var x = 0; x < bitmap.Width; x++)
            {
                for (var y = 0; y < bitmap.Height; y++)
                {
                    var pixelColor = this.GetPixelColor(x, y);
                    pixelColor.B = pixelColor.B.SetLeastSignificantBit(bitmap.GetPixelColor(x, y).Equals(Colors.White));
                    this.SetPixelColor(x, y, pixelColor);
                }
            }

            if (encrypt)
            {
                this.flipEmbeddedImage();
            }
            this.setUpHeaderForSecretImage(encrypt);
        }
示例#2
0
 private void flipEmbeddedImage()
 {
     this.EmbedMonochromeImage(MonochromeBitmap.FromEmbeddedSecret(this).GetFlipped(), false);
 }