Java 图像隐写术
我试图解码图像中编码的数据。编码工作正常,图像的数据大小也会改变,但由于某种原因,解码的数据是一个空字符串。要么编码数据丢失,要么此代码有错误Java 图像隐写术,java,image,bufferedimage,steganography,Java,Image,Bufferedimage,Steganography,我试图解码图像中编码的数据。编码工作正常,图像的数据大小也会改变,但由于某种原因,解码的数据是一个空字符串。要么编码数据丢失,要么此代码有错误 int temp,tempText=0,x=0,p=0; try { image= ImageIO.read(new File("C:\\Users\\Desktop\\Encoded.png")); } catch (IOException e) { e.printStackT
int temp,tempText=0,x=0,p=0;
try
{
image= ImageIO.read(new File("C:\\Users\\Desktop\\Encoded.png"));
}
catch (IOException e)
{
e.printStackTrace();
}
for(int i=0;i<image.getWidth();i++)
{
for(int j=0;j<image.getHeight();j++)
{
pixels[i][j]=image.getRGB(i, j);
}
}
for(int i=0;i<Width;i++)
{
for(int j=0;j<Height;j++)
{
temp=pixels[i][j];
int change=0;
for(int k=0;k<4;k++) // 4 iterations for 4bytes of every pixel
{
if(k==0)
{
change=1;
}
else
if(k==1)
{
change=256;
}
else
if(k==2)
{
change=65536;
}
else
if(k==3)
{
change = 16777216;
}
tempText=tempText | (pixels[i][j] & change);
p++;
if(p==8) // because character is of 8bits
{
myString.concat(String.valueOf(tempText));// Writing decoded data in string
p=0;
tempText=0;
}
}
}
// Writing in file
try
{
file = new File("C:\\Users\\Desktop\\Retreive.txt");
fw = new FileWriter(file);
bw= new BufferedWriter(fw);
bw.write(myString);
bw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
如果我犯了任何错误或此代码缺少任何内容,请通知我。String.concat不会更改调用它的字符串,而是返回一个新字符串。所以如果使用myString=myString.concat。。。相反,您可能会得到更好的结果。如果试探文本包含字符代码,则可以将其转换为字符,因为String.valueOf返回int的字符串表示形式:
// Writing decoded data in string
// myString = myString.concat(String.valueOf(tempText));
myString += (char) tempText;
而不是:
myString.concat(String.valueOf(tempText));// Writing decoded data in string
为了更快地获得更好的帮助,请发布一个。你在哪里初始化宽度和高度?嘿,我只需要清理一下这些东西。那么,你的algo LSB替换成功了吗?最后一个字符的错误是什么?还是没有成功。我想把全部代码发给你。你可能会得到一个更好的想法,通过看完整的程序抱歉听到。。。你能把你所有的代码都放在上面的问题中吗?或者用其他方式提供它?我找到了你的代码,我正在查看它。project2.png文件是否有特殊要求,或者是否可以使用任何png文件?让我们来看看