title: NDK - Save Bitmap's pixels to File
body: <p>I'm currently trying to save a bitmap using the NDK without restoring the Java Object but using directly a C++ pixel array.</p>
  
  <p>I have already the bitmap stored in a JniBitmapHolder and I can successfully get the stored pixels. I would like to try to save them without call the Bitmap.create method.</p>
  
  <p>Currently I'm trying to do it like this (without success):</p>
  
  <pre><code>Util.saveImageSync(Util.getOutputMediaFile("filtered"), jniBitmap.getBitmapArray());
  </code></pre>
  
  <p>And the method is implemented like this:</p>
  
  <pre><code>public static void saveImageSync(final File outputFile, final ByteBuffer buffer){
      FileOutputStream out = null;
      try {
          out = new FileOutputStream(outputFile);
          out.getChannel().write(buffer);
      } catch (Exception e) {
          Dbg.d("ERROR", e);
      } finally {
          try {
              if (out != null) {
                  out.close();
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I've added the method getBitmaArray to the library, like this:</p>
  
  <pre><code>JNIEXPORT jobject JNICALL Java_com_jni_bitmap_1operations_JniBitmapHolder_jniGetBitmapArray(
      JNIEnv * env, jobject obj, jobject handle) {
  JniBitmap *jniBitmap = (JniBitmap *) env-&gt;GetDirectBufferAddress(handle);
  jniBitmap-&gt;_storedBitmapPixels;
  return env-&gt;NewDirectByteBuffer(jniBitmap-&gt;_storedBitmapPixels, 0);
  </code></pre>
  
  <p>}</p>
  
  <p>But it seems that the direct pixel array isn't enough or correct. Any other idea to save pixels directly to file without the need of creating the Java Bitmap?</p>
  
  <p>Also hints/pointers are really appreciated. </p>