Question

i know it may be easy but i couldn't able to find a solution for this.

i need to get the next row of bitmap after using all the bitmap of current bitmap I'm making a stenography program where I'm hiding a text file inside image. Each character is stored inside 8 different bytes. so after hiding text inside 1st column i need to get next column and so on. I'm very weak in this. I tried this for 1st row, but don't know for other rows according to text length.

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

                    }
                }}
Was it helpful?

Solution

How about this?

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

For example, if you have a width of 10, these should be the coordinates for the first two letters of your text:

Letter 1:

(0, 0)

...

(0, 7)

Letter 2:

(0, 8)

(0, 9)

(1, 0)

...


IMPORTANT NOTE: It looks like you don't hide the length of the text and the decoding process won't know how many pixels to read to retrieve the message.

If you have dealt with it somewhere else, or the decoder always knows the length, that's fine. Otherwise, you want to use a set number of pixels at a fixed location (usually the first 32), to encode in binary the length of your text. For example,

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

For the text "Hello World", binary will be 00000000000000000000000001011000. Now you can embed these in your 32 specific pixels and the actual secret message afterwards. Remember that in this case your image must have at least 8 * TextBox1.Text.Length + 32 number of pixels to accommodate the whole secret.

Using 4 bytes for the length of the text is such an overkill, considering, above all, image size limitations. You can use fewer bytes if you can always guarantee the text size will never exceed a specific length, or a more dynamic approach, like this

Reference: Integer to binary string conversion borrowed from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top