Home Sending drawable as byte array to jni part of android
Reply: 0

Sending drawable as byte array to jni part of android

user2009 Published in March 20, 2018, 5:29 pm

I am working on Image Processing with OpenCv on Android. In OpenCv examples as Tutorial 3, they are using native code, and they are sending frame data from java part to jni part as byte array. Then they are converting byte array to mat. Lastly they are processing mat variable and return this for show.

Like this, i want to send drawable to jni part. So firstly i convert drawable to bitmap, and bitmap to byte array like this;

private Bitmap my_bitmap;
private byte[] process_data;
Drawable myDrawable = getResources().getDrawable(R.drawable.test);
my_bitmap = ((BitmapDrawable) myDrawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mybitmap.compress(CompressFormat.PNG, 100, stream);
process_data = stream.toByteArray();

Then i send this byte array to jni part then i give int array from jni and create bitmap;

int[] rgba = mRGBA;
Test(p_width, p_height, process_data, rgba); //This is jni function

Bitmap bmp = Bitmap.createBitmap(p_width, p_height, Bitmap.Config.ARGB_8888);
bmp.setPixels(rgba, 0, p_width, 0, 0, p_width, p_height);

But the return bitmap is like noise.

This is my c++ code;

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_Test(JNIEnv* env, jobject thiz, 
jint width, jint height, jbyteArray p_data, jintArray bgra)

jbyte* _p_data= env->GetByteArrayElements(p_data, 0);
jint* _bgra = env->GetIntArrayElements(bgra, 0);

Mat mdata(height, width, CV_8UC4, (unsigned char *)_p_data);
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);


env->ReleaseIntArrayElements(bgra, _bgra, 0);
env->ReleaseByteArrayElements(p_data, _p_data, 0);

Probably, i make a mistake type of converting. Because i can't find any information about how many channel is my drawable after converting byte. I am waiting for your help to solve my problem.

Thanks in advance.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.421423 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO