0

我试图从网站上阅读这一段,但我不明白为什么“第 32 个像素存储重建创建原始字符串所需的字节值所需的位”。

这是试图将消息放入 alpha(透明度)(ARGB)

在下面的这段代码中,为什么需要同时嵌入整数和字节

 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++;
         }
      }
   }
4

1 回答 1

1

您需要存储消息长度,以便知道要读取多少像素才能提取消息。因为无法预测消息的长度,所以分配了 32 位(用于前 32 个像素)。

函数 embedInteger 和 embedByte 几乎相似。

  • embedInteger处理在前 32 个像素中嵌入消息的长度。
  • embedByte一个一个地嵌入您的消息字符。每次调用它时,它都会以字节形式将消息中的下一个字符作为输入,b[i]. 在那里,它每个像素嵌入一位,每个字节总共 8 位。
于 2014-01-21T15:00:21.147 回答