title: android, java, simple bitmap encoding
body: <p>I need to download bitmap, encode it and save to sd card.
  I have no problems with 1st and 3rd steps, but with 2nd.
  I don't need sophisticated encoding algorithm, so I just reverse byte array which is received during download:</p>
  
  <pre><code>private static byte[] vice_versa(byte[] bytes) {
      if (bytes == null) {
          assert false;
          return null;
      }
      byte[] result = new byte[bytes.length];
      for (int i = 0; i &lt; bytes.length; i++) {
          result[bytes.length - 1 - i] = bytes[i];
      }
      return result;
  }
  </code></pre>
  
  <p>and save it to sd card:</p>
  
  <pre><code>public boolean saveToFile(byte[] bytes) {
          ...
          bytes = vice_versa(bytes);
          out = new FileOutputStream(getFile());
          out.write(bytes);
          ...
  </code></pre>
  
  <p>I load saved file like this:</p>
  
  <pre><code>            ...
              byte[] bytes = FileUtils.readFileToByteArray(getFile());
              bytes = vice_versa(bytes);              
              Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, 0);
              ...
  </code></pre>
  
  <p>However, BitmapFactory  cannot decode byte array and returns null. I am able to compare decoded byte stream, with original byte stream. Stream lengths are same, all bytes are same, but Object.equals returns false. How is it possible and what is going on?</p>