1 Attachment(s)
java.lang.IllegalArgumentException: im == null!
I am getting the following output after executing the attached code:
Quote:
Available: 109980
Reader is not found
Image is NULL
java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at Main_TEST.main(Main_TEST.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.ru nCommand(JavacCompiler.java:271)
Can anyone please give me a solution to this problem, or can anyone suggest me any alternative ways to write image after bit-manipulation.
Thanks in advance in anticipation of an early reply.
Code Java:
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;
import java.util.Iterator;
public class Main_TEST {
public static void main(String[] args) {
try{
//String fileName=new File();
BufferedImage img = ImageIO.read(new File("C:\\test.jpg"));
BufferedImage new_img=new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g=new_img.createGraphics();
g.drawRenderedImage(img, null);
g.dispose();
//convert BufferedImage to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( new_img, "jpg", baos );
baos.flush();
byte[] imageInByte = baos.toByteArray();
//call to steg_process method..
byte[] output_data=steg_process(imageInByte);
//convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(output_data);
//if output_data is replaced by imageInByte and previous line is commented out then new image is created
System.out.println("Available: "+in.available());
new_img = ImageIO.read(in);
//FileInputStream inp=new FileInputStream(new File(fileName));
Iterator i=ImageIO.getImageReaders(in);
if(i.hasNext()){
System.out.println("Reader is found");
}else{
System.out.println("Reader is not found");
}
if(new_img==null){
System.out.println("Image is NULL");
}
File outputfile = new File("saved.jpg");
ImageIO.write(new_img, "jpg", outputfile);
}catch(IOException e){
e.printStackTrace();
}
}
// This method is for manipulating byte[] array, change some of it's bits and then return the modified byte[]
private static byte[] steg_process(byte[] orig_data){
byte a=0;
orig_data[0]=a;
return orig_data;
}
}