【问题标题】:Storing message into image将消息存储到图像中
【发布时间】:2014-02-10 06:43:52
【问题描述】:

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

这是试图将消息放入 alpha (transparency)(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++;
         }
      }
   }

【问题讨论】:

    标签: image embed bufferedimage steganography argb


    【解决方案1】:

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

    embedInteger 和 embedByte 函数几乎相似。

    • embedInteger 处理在前 32 个像素中嵌入消息的长度。
    • embedByte 会一一嵌入您的消息字符。每次调用它时,它都会以字节形式输入消息中的下一个字符b[i]。在那里,它每个像素嵌入一位,每个字节总共 8 位。

    【讨论】:

    • 谢谢回复,embedInteger是处理嵌入消息的前32个像素的长度??但是 embedByte 呢??
    • 对不起,这可能是一个愚蠢的问题,为什么需要 embedInteger,因为我们可以使用 embedByte 将消息一一嵌入。每个像素只能嵌入一位吗?
    • 因为我试图将二进制文件的字节数组(128字节)嵌入到图像中,但是当我试图提取字节数组时,它与我放入的不是同一个。因为它太大??
    • 区别很微妙。 embedInteger 接受消息长度为整数 (int n) 并且嵌入限制为 32。embedByte 接受字节形式的消息字符 (byte b),它是使用 byte b[] = mess.getBytes() 转换的。稍作修改,你可以为 messageLength 和 message 设置一个函数,但作者没有选择。
    • 我不太明白你在那里尝试做什么以及为什么失败。
    猜你喜欢
    • 2015-11-01
    • 2021-06-01
    • 2017-07-21
    • 1970-01-01
    • 2019-03-02
    • 2018-09-01
    • 2013-11-23
    • 2013-06-21
    • 2012-02-27
    相关资源
    最近更新 更多