title: Sending image with byte array convertion, from java to c#
body: <p>I am trying to send a .jpg file which is on my android device to my server computer.</p>
  
  <p>To do this, I am converting the picture into a byte array by a java android application, and sending it as an argument to my server computer. I`m doing this by a web service call. </p>
  
  <p><strong>The first function is edited:</strong></p>
  
  <pre><code>public static byte[] ImageConvertion(){
  
      File inputFile = new File("/storage/emulated/0/IFSpictures/icon-si_strapclamp.jpg");
      byte[] data;
  
      try{
          FileInputStream input = new FileInputStream(inputFile);
          ByteArrayOutputStream output = new ByteArrayOutputStream ();
  
          byte[] buffer = new byte[65535];
  
          int l;
  
          while ((l = input.read(buffer)) &gt; 0)
              output.write (buffer, 0, l);
  
          input.close();
          output.close();
  
          data = output.toByteArray();
          return data;
  
  
      } catch (IOException e) {
          System.err.println(e);
          data=null;
      }
      return data;
  
  }
  </code></pre>
  
  <p>My web-service is written in ASP.NET (C#) language, and there is a function that takes the byte array as an argument and converts it back into an image on server computer.</p>
  
  <pre><code>[WebMethod]
  public void ByteArrayToPicture(byte[] imageData)
  {
      using (var ms = new MemoryStream(imageData))
      {
          Image image = Image.FromStream(ms);
          image.Save(@"C:\newImage.jpg");
      }
  }
  </code></pre>
  
  <p>However, I couldn`t do it because of the web-service side. I have debugged it that and it seems that the problem is because of the Image.FromStream() function. </p>
  
  <p>I definitely don`t have any problems with passing the arguments. I think either, the language conflict or the conversion image to byte and vice-verse may be leading the problem. Does anyone has any idea or see something wrong? </p>
  
  <p>I muchly appropriate any help. </p>
  
  <p>Thanks.</p>