4 Replies Latest reply: Feb 24, 2010 12:05 PM by 843802 RSS

    IOImage.write showing error after byte[] to BufferedImage

    843802
      I am new to Image Manipulations in Java and I am writing some program related to Image Steganography by Mapping Pixels to Letters..

      I have successfully read the data from gray scale image to BufferedImage object and read the pixels in byte array..
      byte []data;
      DataBufferByte buffer = (DataBufferByte) image.getRaster().getDataBuffer();
      data = buffer.getData();
      Now for testing the working of my pixel morphing I have changed two pixels data[0] and data[1] and tried to store it in some target.jpg file.. For that I used
      image.data[0]=(byte)3;
      image.data[1]=(byte)1;
      InputStream in = new ByteArrayInputStream(image.data);
          try {
                  BufferedImage img = javax.imageio.ImageIO.read(in);
                  image.write(img, ref);
              } catch (IOException ex) {
                  Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
              }
      Now I am getting error because ImageIO.read is returning NULL to BufferedImage img.. hence write method is throwing IllegalArgumentException.

      I am totally lost.. please help me..

      Edited by: Neo_Cerf on Feb 22, 2010 8:01 PM