title: Convert Tif image to byte[]
body: <p>I tried to convert Tiff image to Byte[] but <strong>getting exception from java 1.8 sdk</strong>. I searched in google but did not get solution yet. <strong>Same code works for java 1.6</strong>.  </p>
  
  <pre><code>public static byte[] convertImage(String dirName, String imageName)
  {
      try
      {
      //String dirName="C:\\Temp\\";
      ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
      BufferedImage img=ImageIO.read(new File(dirName,imageName));
  
      ImageIO.write(img, "tif", baos);
      baos.flush();
  
      byte[] bytearray = baos.toByteArray();
  
      baos.close();
  
      return bytearray;
      }
      catch(IOException ioe)
      {
          ioe.printStackTrace();
      }
      catch(Exception ex)
      {
          ex.printStackTrace();
      }
      return null;
  
  }
  </code></pre>
  
  <p>variable <strong>img</strong> is always null in java 1.8 but 1.6 returns info.</p>
  
  <p>Exception raised from sdk 1.8 as follows</p>
  
  <pre><code>java.lang.IllegalArgumentException: image == null!
  at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(Unknown Source)
  at javax.imageio.ImageIO.getWriter(Unknown Source)
  at javax.imageio.ImageIO.write(Unknown Source)
  at test.practice.net.ConverterImageUsing18.convertImage(ConverterImageUsing18.java:88)
  at test.practice.net.ConverterImageUsing18.GetBase64BinaryAsString(ConverterImageUsing18.java:52)
  at test.practice.net.ConverterImageUsing18.main(ConverterImageUsing18.java:42)
  </code></pre>
  
  <p>Any hits or sample code is appreciable. </p>