Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: java.lang.IllegalArgumentException: im == null!

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Thanked 0 Times in 0 Posts

    Default java.lang.IllegalArgumentException: im == null!

    I am getting the following output after executing the attached code:
    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.

    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) {
                //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);
                //convert BufferedImage to byte array
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageIO.write( new_img, "jpg", baos );
                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);
                    System.out.println("Reader is found");
                    System.out.println("Reader is not found");
                    System.out.println("Image is NULL");
                File outputfile = new File("saved.jpg");
                ImageIO.write(new_img, "jpg", outputfile);             
            }catch(IOException e){
        // 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;
            return orig_data;
    Attached Files Attached Files

Similar Threads

  1. java.lang.IllegalArgumentException: Identifier not found
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 9th, 2012, 04:48 AM
  2. Replies: 0
    Last Post: August 30th, 2010, 07:34 AM
  3. IllegalArgumentException: Pan not supported
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 13th, 2010, 01:00 PM
  4. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM