Question

I tried to read this paragraph from a website, but i don not understand why "32nd pixel store the bits needed for reconstructing the byte value needed to create the original string."

This is trying to put the message into alpha (transparency)(ARGB)

In this code below, why need to embed both integer and byte

 int imageWidth = img.getWidth(), imageHeight = img.getHeight(),
 imageSize = imageWidth * imageHeight;
 if(messageLength * 8 + 32 > imageSize) {
    JOptionPane.showMessageDialog(this, "Message is too long for the chosen image",
       "Message too long!", JOptionPane.ERROR_MESSAGE);
    return;
   }
   embedInteger(img, messageLength, 0, 0);

   byte b[] = mess.getBytes();
   for(int i=0; i<b.length; i++)
      embedByte(img, b[i], i*8+32, 0);
   }

 private void embedInteger(BufferedImage img, int n, int start, int storageBit) {
   int maxX = img.getWidth(), maxY = img.getHeight(), 
      startX = start/maxY, startY = start - startX*maxY, count=0;
   for(int i=startX; i<maxX && count<32; i++) {
      for(int j=startY; j<maxY && count<32; j++) {
         int rgb = img.getRGB(i, j), bit = getBitValue(n, count);
         rgb = setBitValue(rgb, storageBit, bit);
         img.setRGB(i, j, rgb);
         count++;
         }
      }
   }

private void embedByte(BufferedImage img, byte b, int start, int storageBit) {
   int maxX = img.getWidth(), maxY = img.getHeight(), 
      startX = start/maxY, startY = start - startX*maxY, count=0;
   for(int i=startX; i<maxX && count<8; i++) {
      for(int j=startY; j<maxY && count<8; j++) {
         int rgb = img.getRGB(i, j), bit = getBitValue(b, count);
         rgb = setBitValue(rgb, storageBit, bit);
         img.setRGB(i, j, rgb);
         count++;
         }
      }
   }
Was it helpful?

Solution

You need to store the message length so you know how many pixels to read to extract the message. Because the length of the message can't be predicted, 32 bits (for the first 32 pixels) are allocated.

The functions embedInteger and embedByte are almost similar.

  • embedInteger deals with embedding the length of the message in the first 32 pixels.
  • embedByte embeds your message characters, one by one. Every time it is called upon, it takes as an input the next character in your message in byte form, b[i]. There, it embeds one bit per pixel, for a total of 8 bits per byte.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top