Image 将消息存储到图像中
我试着从一个网站上读这段话,但我不明白为什么“32像素存储重建创建原始字符串所需字节值所需的位。” 这是试图将消息放入alpha(透明度)(ARGB) 在下面的代码中,为什么需要同时嵌入整数和字节Image 将消息存储到图像中,image,embed,bufferedimage,steganography,argb,Image,Embed,Bufferedimage,Steganography,Argb,我试着从一个网站上读这段话,但我不明白为什么“32像素存储重建创建原始字符串所需字节值所需的位。” 这是试图将消息放入alpha(透明度)(ARGB) 在下面的代码中,为什么需要同时嵌入整数和字节 int imageWidth = img.getWidth(), imageHeight = img.getHeight(), imageSize = imageWidth * imageHeight; if(messageLength * 8 + 32 > imageSize) {
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++;
}
}
}
int-imageWidth=img.getWidth(),imageHeight=img.getHeight(),
图像大小=图像宽度*图像高度;
如果(messageLength*8+32>imageSize){
showMessageDialog(此“消息对于所选图像太长”,
“消息太长!”,作业窗格。错误消息);
返回;
}
嵌入整数(img,messageLength,0,0);
字节b[]=mess.getBytes();
对于(int i=0;i您需要存储消息长度,以便知道提取消息需要读取多少像素。由于无法预测消息的长度,因此分配了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使用一个函数,但作者没有选择。我不太明白您在那里尝试了什么以及失败的原因。