从Android Native函数中的字节数组中读取像素

时间:2017-08-01 06:19:33

标签: android arrays image-processing android-ndk pixels

我试着读取从相机获得的每一帧的像素数据。我想使用本机代码来提高性能。我将frame.image(字节数组)传递给本机func,并期望得到像素(int数组)。然后我将这些像素设置为位图。

Java Side:

if (bitmap == null) {
    int bitmapHeight = frame.size.height;
    int bitmapWidth = frame.size.width;

    bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    pixel = new int[bitmapWidth * bitmapHeight];}

imageProcessing(frame.size.width, frame.size.height, frame.image, pixel);
bitmap.setPixels(pixel, 0, frame.size.width, 0, 0, frame.size.width, frame.size.height);
NDK方面:我对这方面知之甚少。目前返回零int数组

Java_com_app_myapp_ui_camera_CameraFragment_imageProcessing(
    JNIEnv* env, jobject thiz,
    jint width, jint height,
    jbyteArray NV21FrameData, jintArray outPixels)
{
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);


//Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
//Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}

那么如何在imageProecessing func中填充像素?

0 个答案:

没有答案