I'm currently trying to save a bitmap using the NDK without restoring the Java Object but using directly a C++ pixel array.
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.
Currently I'm trying to do it like this (without success):
Util.saveImageSync(Util.getOutputMediaFile("filtered"), jniBitmap.getBitmapArray());
And the method is implemented like this:
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();
}
}
}
I've added the method getBitmaArray to the library, like this:
JNIEXPORT jobject JNICALL Java_com_jni_bitmap_1operations_JniBitmapHolder_jniGetBitmapArray(
JNIEnv * env, jobject obj, jobject handle) {
JniBitmap *jniBitmap = (JniBitmap *) env->GetDirectBufferAddress(handle);
jniBitmap->_storedBitmapPixels;
return env->NewDirectByteBuffer(jniBitmap->_storedBitmapPixels, 0);
}
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?
Also hints/pointers are really appreciated.