【问题标题】:Iterate the bitmap rows and column迭代位图行和列
【发布时间】:2014-05-27 04:32:54
【问题描述】:

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

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

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
                                }
                            }

                    }
                }}

【问题讨论】:

标签: c# bitmap steganography


【解决方案1】:

这个怎么样?

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借来的整数到二进制字符串的转换。

【讨论】:

  • 非常感谢。我有隐藏代码。唯一困扰我的是公式。谢谢你。
猜你喜欢
  • 2012-10-11
  • 2018-03-22
  • 2018-08-03
  • 2014-05-15
  • 2021-01-07
  • 2014-06-29
  • 2020-10-16
  • 2017-04-03
  • 2017-03-18
相关资源
最近更新 更多