MCPcopy Create free account
hub / github.com/devilsen/CZXing / BitmapToMat

Function BitmapToMat

czxing/src/main/cpp/JNIUtils.cpp:43–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41} // anonymous
42
43void
44BitmapToMat(JNIEnv *env, jobject bitmap, cv::Mat &mat) {
45 AndroidBitmapInfo bmInfo;
46 if (AndroidBitmap_getInfo(env, bitmap, &bmInfo) != ANDROID_BITMAP_RESULT_SUCCESS) {
47 LOGE("nBitmapToMat: get bitmap info error");
48 return;
49 };
50
51 void *pixels = nullptr;
52 if (AndroidBitmap_lockPixels(env, bitmap, &pixels) == ANDROID_BITMAP_RESUT_SUCCESS) {
53 AutoUnlockPixels autounlock(env, bitmap);
54
55 if (bmInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) {
56 LOGE("nBitmapToMat: RGB_8888 -> CV_8UC4");
57 cv::Mat tmp(bmInfo.height, bmInfo.width, CV_8UC4, pixels);
58 tmp.copyTo(mat);
59 } else {
60 // info.format == ANDROID_BITMAP_FORMAT_RGB_565
61 LOGE("nBitmapToMat: RGB_565 -> CV_8UC4");
62 cv::Mat tmp(bmInfo.height, bmInfo.width, CV_8UC4, pixels);
63 tmp.copyTo(mat);
64 }
65 } else {
66 throw std::runtime_error("Failed to read bitmap's data");
67 }
68}
69
70void ThrowJavaException(JNIEnv *env, const char *message) {
71 static jclass jcls = env->FindClass("java/lang/RuntimeException");

Callers 1

readBitmapMethod · 0.85

Calls 1

copyToMethod · 0.45

Tested by

no test coverage detected