Can I create bitmaps from Android NDK in C ++ and quickly transfer them to Java?

I need to create bitmaps in C ++ using ndk and pass them to Java. I do not mean a copy, but actually pass them as a parameter or return value or something else like that, because copying them will be too slow. I also really need to create them in the NDK part, and not in java.

Does anyone know how to do this?

+5
source share
3 answers

As Peter Lowry has already pointed out, using an object other than Java is not possible, but it may be possible to directly draw raw data from a simple array of Java bytes (which can be directly accessed on the C ++ side).

In the end, you could even call Canvas.drawBitmap (..) , using this byte array to draw your created image. Of course, to store the image on the C ++ side, you need to save the required format inside the byte array.

Java:

byte[] pixelBuf = new byte[bufSize];

Then pass the link byte[]to the C ++ inline implementation. On the C ++ side, you can call

C ++:

jbyte* pixelBufPtr = env->GetByteArrayElements(pixelBuf, JNI_FALSE);
jsize pixelBufLen = env->GetArrayLength(env, pixelBuf);
// modify the data at pixelBufPtr with C++ functions
env->ReleaseByteArrayElements(pixelBuf, pixelBufPtr, 0);
+7
source

ByteBuffer. ByteBuffer . Java Java. Java C, , , C Java.

+1

, ++, "" Java. "" NDK, Android 2.2; -. , . , .

0

All Articles