您需要将 YUV 图像转换为 RGBA 图像。
cv::Mat _yuv(height+height/2, width, CV_8UC1, (uchar *)imagebuffer);
cv::cvtColor(_yuv, _yuv, CV_YUV2RGBA_NV21);
通常,YUV 图像是带有1.5*height 的 1 通道图像(如果是 RGB 或灰度图像)。
或者您可以创建一个新的 Mat 并将 jint 数组传递给本机函数并使用该数组来设置位图的像素。
jint *_out = env->GetIntArrayElements(out, 0);
cv::Mat _yuv(height + height/2, width, CV_8UC1, (uchar*)imagebuffer);
cv::Mat _rgba(height, width, CV_8UC4, (uchar *)_out);
cv::cvtColor(_yuv, _rgba, CV_YUV2RGBA_NV21);
env->ReleaseIntArrayElements(out, _out, 0);
在 Java 中,
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
pixels = new int[width * height];
native_function(height, width, bytedata, pixels);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);