我编写了将消息隐藏到图像中的代码,起初我将图像转换为字节数组并将消息隐藏到图像中,但是当我想将新的字节数组转换为图像时,我得到了null
?我知道关于这个话题有很多问题,我尝试了答案但没有用。请问有人可以帮我吗?
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
//import javax.swing.text.html.HTMLDocument.Iterator;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import java.util.Iterator;
public class test {
public static void main(String[] args) throws IOException{
if(args.length==0)
{
String dirName="C:\\";
ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
BufferedImage img=ImageIO.read(new File("inacup_donut.jpg"));
ImageIO.write(img, "jpg", baos);
baos.flush();
String base64String=Base64.encode(baos.toByteArray());
baos.close();
byte[] bytearray = Base64.decode(base64String);
int [] int_array=new int [bytearray.length];
for(int i=0;i<bytearray.length;i++)
{
int_array [i]=(int)bytearray[i];
}//end for loop
int x []= encodeMessage(int_array,img.getHeight(),img.getWidth(),
"message") ;
System.out.println("read " + x[0]+ " bytes,");
byte [] new_bytearray = new byte [x.length] ;
for(int i=0;i<x.length;i++)
{
new_bytearray[i]=(byte)x[i];
}//end for loop
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(new_bytearray));
ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
}
}//end main function
}//end class