title: decodeByteArray data from onPictureTaken callback returns null
body: <p>There are similar questions like this on SO but none of them matches my specific situation. </p>
  
  <p>I am implementing camera controls using the official <a href="https://developer.android.com/guide/topics/media/camera.html#custom-camera" rel="nofollow">tutorial</a>. </p>
  
  <p>The way I take shot is by invoking <code>mCamera.takePicture(null, null, this)</code> and then receiving the callback from <code>onPictureTaken</code>. The problem I am having is I can't seem to <code>decodeByteArray</code> the data being passed onto <code>onPictureTaken</code>. <code>decodeByteArray</code> keeps on returning null. It seems the format of the byte array is invalid.  </p>
  
  <p>I tried saving the byte array via a <code>FileOutputStream</code> as is, just as in the tutorial and then read the bytes back again via <code>decodeFile</code> and it still returns null. I tried capturing exceptions but none was caught. </p>
  
  <p>Take note that I can save the photo just fine. I cannot read the bytes from the argument passed. I can't seem to figure this out.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@Override
  public void onPictureTaken(byte[] data, Camera camera)
  {
      FileOutputStream out = null;
      String fileName =  Photo.getDirectory(this) + "/Confirm_" + mDateFormatter.format(new Date()) + ".jpg";
  
      try
      {
          File temp = new File(fileName);
          out = new FileOutputStream(temp);
          out.write(data);
          out.close();
  
          try
          {
              // This always returns NULL
              BitmapFactory.Options option = new BitmapFactory.Options();
              option.inJustDecodeBounds = true;
              option.inSampleSize = 2;
              Bitmap bitmap = BitmapFactory.decodeFile(fileName, option);
  
              if(bitmap == null) ; // TRUE
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
  
          /*
          Camera.Parameters param = mCamera.getParameters();
          List&lt;Camera.Size&gt; sizes = param.getSupportedPictureSizes();
          Bitmap bitmap = BitmapFactory.decodeFile(fileName);
  
          for(Camera.Size s : sizes)
          {
              Log.i(PhotoApplication.TAG, "Size : " + s.width + " x " + s.height);
          }
          */
  
          Intent intent = new Intent();
          intent.putExtra(EXTRA_FILENAME, temp.getAbsolutePath() + "/" + temp.getName());
          setResult(RESULT_OK, intent);
  
          Toast.makeText(this, "Saving as : " + temp.getAbsolutePath() + "/" + temp.getName(), Toast.LENGTH_LONG).show();
      }
      catch(FileNotFoundException e)
      {
  
      }
      catch(IOException e)
      {
  
      }
      finally
      {
          try
          {
              if(out != null)
                  out.close();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
      }
  
      finish();
  }
  </code></pre>