I'm attempting some Bitmap manipulation in Java with C++ reading the data. I'm about to work on a roundabout that eliminates the jobject passing to and fro causing me problems but would like to know what I'm doing wrong.
Basic flow is:
Java grabs a Bitmap from the device.
Bitmap is passed to C++ (received as jobject).
C++ asks Java for sub crop of object, or for its data as jpg data that we then load into a UTexture2D.
This flow is not my first choice, but a work around for ReadPixels not working on mobile devices.
The problem I have is that the Java jobject I am returned is being complained about by the JNI when I pass it back to Java (my workaround is going to be to store it in the java only).
This is the output
10-06 17:41:07.831 23059 23059 E ARToolKitLog: LOOKHERE: ***Test scale fn (1)
10-06 17:41:07.831 23059 23059 E ARToolKitLog: LOOKHERE: ***AndroidThunkJava_ScaleImage: android.graphics.Bitmap@dd06274 w:32 h:32
10-06 17:41:07.833 23059 23059 E ARToolKitLog: LOOKHERE: ***Returning to C++
This line comes next, from C++ (function - the image resolution returned to C++ is probably correct I haven't checked)
10-06 17:41:07.834 23059 23059 I CameraLOG: LOOKHERE: test scale of image: ff8229c0 (3036 x 4048)
And then a JNI error.
10-06 17:41:07.874 23059 23059 F zygote : java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: thread Thread[1,tid=23059,Native,Thread*=0xe8ac5000,peer=0x72cd9568,"main"] using JNIEnv* from thread Thread[12,tid=23100,Runnable,Thread*=0xdf5a3400,peer=0x12dc06e8,"Thread-2"]
A little further in the output we see this.
10-06 17:41:07.875 23059 23059 F zygote : java_vm_ext.cc:504] native: #13 pc 093a59ec /data/app/com.MatchyMaximus.Matchoo-udeLgRRxh3lx5V2366qIaA==/lib/arm/libUE4.so (_Z26AndroidThunkCpp_ScaleImageP8_jobjectii+152)
In Java we have this (response to a game activity)
bmp = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
android.util.Log.e("ARToolKitLog", "LOOKHERE: ***Test scale fn (1)");
AndroidThunkJava_ScaleImage(bmp, 32, 32);
android.util.Log.e("ARToolKitLog", "LOOKHERE: ***Returning to C++");
CPPOnCameraResult(true, bmp, bmp.getWidth(), bmp.getHeight());
} catch (FileNotFoundException ex)
The Java scale image function looks like this:
public Object AndroidThunkJava_ScaleImage(Object _img, int width, int height)
android.util.Log.e("ARToolKitLog", "LOOKHERE: ***AndroidThunkJava_ScaleImage: " + _img + " w:" + width + " h:" + height);
Bitmap bmp = (Bitmap)_img;
return Bitmap.createScaledBitmap(bmp, width, height, false);
This function tries (for testing purposes) to throw the image back to java and fails.
extern "C" void Java_com_epicgames_ue4_GameActivity_CPPOnCameraResult(JNIEnv* LocalJNIEnv, jobject LocalThiz, jboolean success, jobject img, jint width, jint height)
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "LOOKHERE: test scale of image: %x (%d x %d)", (int)img, width, height);
AndroidThunkCpp_ScaleImage(img, 32, 32);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "LOOKHERE: test scale of image PASSED");
FAndroidCameraModule::ReturnImageToCPP(success, img, width, height);
Full log is attached.
Oct 07 '17 at 01:13 AM
in C++ Programming