title: Sending image from android to PC via bluetooth
body: <p>I'm making an app to send an image from an android device to a java app running on a PC. The image on the client side (android) is a <code>Bitmap</code> and I convert it to a <code>Byte Array</code> in order to send it to the server via bluetooth.</p>
  
  <pre><code> ByteArrayOutputStream baos = new ByteArrayOutputStream();  
   ImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);     
   byte[] b = baos.toByteArray();
   mBluetoothService.write(b);
  </code></pre>
  
  <p>Note that the bitmap comes from an already compressed file, so I don't need to compress it again.</p>
  
  <p>I use the following code on the server (Java):</p>
  
  <pre><code>  byte[] buffer = new byte[1024*1024];
    int bytes;
    bytes = inputStream.read(buffer);
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
    BufferedImage image = ImageIO.read(bais);
    ImageIO.write(image, "jpg", new File("c:/users/image.jpg"));
  </code></pre>
  
  <p>There are no error on the client side. But I get this exception on the server side (java app):</p>
  
  <p>java.lang.IllegalArgumentException: im == null!</p>
  
  <p>at javax.imageio.ImageIO.write(Unknown Source)</p>
  
  <p>at javax.imageio.ImageIO.write(Unknown Source)</p>
  
  <p>at com.luugiathuy.apps.remotebluetooth.ProcessConnectionThread.run(ProcessConnectionThread.java:68)</p>
  
  <p>at java.lang.Thread.run(Unknown Source)</p>
  
  <p>So the <code>ImageIO.read()</code> is not returning anything. It seems like it doesn't recognize the byte array as an image. I have searched on internet but nothing that helps me solve this. Does anyone have any idea?</p>
  
  <p>Many thanks!!</p>