迭代位图行和列

时间:2014-04-13 05:14:03

标签: c# bitmap steganography

我知道这可能很容易,但我无法找到解决方案。

我需要在使用当前位图的所有位图后获取下一行位图 我正在制作一个速记计划,我在图像中隐藏了一个文本文件。 每个字符存储在8个不同的字节中。 所以在将文本隐藏在第1列之后我需要获得下一列等等。 我在这方面很弱。我尝试了第一行,但根据文本长度不知道其他行。

private void HIDE(){
                if (textBox1.Text != "")
                {
                    Bitmap bitmap = (Bitmap)pictureBox1.Image;
                    int next,width=0;
                    for (int t = 0; t < textBox1.Text.Length; t++)
                    {
                        next = 8 * t;
                            for (int i = 0; i < 8; i++)
                            {
                                if (i * t <= bitmap.Width/8)
                                {
                                     //hiding code for 1st row
                                }
                                else 
                                {
                                    //hiding code for 2nd row
                                }
                            }

                    }
                }}

1 个答案:

答案 0 :(得分:0)

这个怎么样?

private void HIDE(){
              if (textBox1.Text != "")
              {
                  Bitmap bitmap = (Bitmap)pictureBox1.Image;
                  // Starting point for embedding secret
                  int x0=0, y0=0;
                  // Error checking, to see if text can fit in image
                  int imageSize = bitmap.Width * bitmap.Height;
                  if (imageSize - x0 * bitmap.Width - y0 < 8 * textBox1.Text.Length)
                  {
                      // Deal with error
                  }
                  // Ready to embed
                  for (int t = 0; t < textBox1.Text.Length; t++)
                  {
                      for (int i = 0; i < 8; i++)
                      {
                          // Check if y0 has exceeded image width
                          // so to wrap around to the new row
                          if (y0 == bitmap.Width)
                          {
                              x0++;
                              y0=0;
                          }
                          // x0, y0 are now the current pixel coordinates
                          //
                          // EMBED MESSAGE HERE
                          //
                          y0++;  // Move to the next pixel for the next bit
                      }
                  }
              }}

例如,如果您的宽度为10,则这些应该是文本前两个字母的坐标:

信1

(0,0)

...

(0,7)

信2

(0,8)

(0,9)

(1,0)

...


重要提示:看起来您没有隐藏文本的长度,解码过程也不知道要读取多少像素来检索邮件。

如果你已经在其他地方处理了它,或者解码器总是知道长度,那很好。否则,您希望在固定位置(通常是前32位)使用一定数量的像素,以二进制编码文本的长度。例如,

int secretLength = 8 * textBox1.Text.Length;
string binary = Convert.ToString(secretLength, 2);

对于文本“Hello World”,二进制文件将为00000000000000000000000001011000。现在您可以将这些嵌入到您的32个特定像素和之后的实际秘密消息中。请记住,在这种情况下,您的图片必须至少有8 * TextBox1.Text.Length + 32个像素数才能容纳整个秘密。

考虑到图像大小的限制,使用4个字节作为文本的长度是一种过度杀伤力。如果您始终可以保证文本大小永远不会超过特定长度,或者使用更加动态的方法,则可以使用更少的字节,例如this

参考:从here借来的二进制字符串转换的整数。