title: Convert image to byte array and viceversa
body: <p>I'm trying to send an image as byte array through android, and convert it back to png file on server side, I'm getting <code>IllegalArgumentException</code> on server side.</p>
  
  <p>This is my android code which converts image to byte array and sends it as request to server:</p>
  
  <pre><code> GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.signaturePad);
  
              Bitmap bm = Bitmap.createBitmap(gestureView.getGesture().toBitmap(100, 100, 8, Color.WHITE));
  
              FileOutputStream fos = openFileOutput("signature.png", Context.MODE_PRIVATE);
              bm.compress(Bitmap.CompressFormat.PNG, 100, fos);
  
              byte[] image_byte = fos.toString().getBytes();//Base64.encode(fos.toString().getBytes(), 0);
  
              String strImage = image_byte.toString();
  </code></pre>
  
  <p>This is my server side program:</p>
  
  <pre><code>String imageString = request.getParameter("SignatureImage");
      byte[] imageByte = imageString.getBytes();
      try {
          InputStream in = new ByteArrayInputStream(imageByte);
          BufferedImage bImageFromConvert = ImageIO.read(in);
  
          //Getting exception at this line
          ImageIO.write(bImageFromConvert, "png", new File(
                  "E:/signature/signature.png"));
          /*BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageByte));
          ImageIO.write(bufferedImage, "jpg", new File("E:/signature/signature.jpg"));*/
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>Exception on server is:</p>
  
  <pre><code>12:39:40,990 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/APDTest].[ImageRetrieve]] Servlet.service() for servlet ImageRetrieve threw exception: java.lang.IllegalArgumentException: im == null!
      at javax.imageio.ImageIO.write(ImageIO.java:1457) [:1.6.0_32]
      at javax.imageio.ImageIO.write(ImageIO.java:1521) [:1.6.0_32]
      at com.apd.test.ImageRetrieve.doPost(ImageRetrieve.java:52) [:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
      at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
  </code></pre>