OCR app crashes giving an error: jni_helper.cc:110 Bitmap is of the wrong format: 4

OCR app crashes giving an error: jni_helper.cc:110 Bitmap is of the wrong format: 4

我正在使用 Google 的视觉 API 来检测图像中的文本。我将它设置在一个 imageview 中并放置一个按钮,然后单击它处理它并显示文本的按钮。如果我单击图片或从图库中上传图片,则效果很好。我也放了一个裁剪选项,当我按下它并在单击处理按钮时设置图像时,应用程序崩溃了。这是我的日志:

A/native: jni_helper.cc:110 Bitmap is of the wrong format: 4
07-15 15:14:35.511 6965-6965/com.cameradetect A/native: terminating.
07-15 15:14:35.512 6965-6965/com.cameradetect A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 6965 (om.cameradetect)
07-15 15:14:35.614 1368-1368/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-15 15:14:35.614 1368-1368/? A/DEBUG: Build fingerprint: 'Android/sdk_google_phone_x86_64/generic_x86_64:6.0/MASTER/3738108:userdebug/test-keys'
07-15 15:14:35.614 1368-1368/? A/DEBUG: Revision: '0'
07-15 15:14:35.614 1368-1368/? A/DEBUG: ABI: 'x86_64'
07-15 15:14:35.614 1368-1368/? A/DEBUG: pid: 6965, tid: 6965, name: om.cameradetect  >>> com.cameradetect <<<
07-15 15:14:35.615 1368-1368/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
07-15 15:14:35.623 1368-1368/? A/DEBUG: Abort message: 'jni_helper.cc:110 Bitmap is of the wrong format: 4
                                    '
07-15 15:14:35.624 1368-1368/? A/DEBUG:     rax 0000000000000000  rbx 00007fce9d1a52c0  rcx ffffffffffffffff  rdx 0000000000000006
07-15 15:14:35.624 1368-1368/? A/DEBUG:     rsi 0000000000001b35  rdi 0000000000001b35
07-15 15:14:35.624 1368-1368/? A/DEBUG:     r8  0000000000000003  r9  0000000000000003  r10 0000000000000008  r11 0000000000000206
07-15 15:14:35.624 1368-1368/? A/DEBUG:     r12 0000000000001b35  r13 0000000000000006  r14 00007fff88f913c8  r15 0000000012ff9970
07-15 15:14:35.624 1368-1368/? A/DEBUG:     cs  0000000000000033  ss  000000000000002b
07-15 15:14:35.624 1368-1368/? A/DEBUG:     rip 00007fce9ccfb447  rbp 0000000000000009  rsp 00007fff88f90c88  eflags 0000000000000206
07-15 15:14:35.626 1368-1368/? A/DEBUG: backtrace:
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #00 pc 0000000000088447  /system/lib64/libc.so (tgkill+7)
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #01 pc 0000000000085b11  /system/lib64/libc.so (pthread_kill+65)
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #02 pc 000000000002e841  /system/lib64/libc.so (raise+17)
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #03 pc 00000000000288fd  /system/lib64/libc.so (abort+61)
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #04 pc 00000000001bd2d1  /data/data/com.google.android.gms/files/com.google.android.gms.vision/ocr/libs/x86_64/libocr.so
07-15 15:14:35.626 1368-1368/? A/DEBUG:     #05 pc 00000000001bd84d  /data/data/com.google.android.gms/files/com.google.android.gms.vision/ocr/libs/x86_64/libocr.so
07-15 15:14:35.607 1368-1368/? W/debuggerd64: type=1400 audit(0.0:58): avc: denied { search } for name="com.google.android.gms" dev="dm-0" ino=114710 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
07-15 15:14:35.627 1368-1368/? A/DEBUG:     #06 pc 000000000004c7ec  /data/data/com.google.android.gms/files/com.google.android.gms.vision/ocr/libs/x86_64/libocr.so
07-15 15:14:35.627 1368-1368/? A/DEBUG:     #07 pc 0000000000118bf0  /data/data/com.google.android.gms/app_chimera/m/00000002/oat/x86_64/DynamiteModulesB_GmsCore_prodmnc_alldpi_release.odex (offset 0x332000)

这是我的裁剪函数:

private void cropImage() {

    try{
        Intent crop =  new Intent("com.android.camera.action.CROP");
        crop.setDataAndType(selectImage, "image/*");
        crop.putExtra("crop", true);
        crop.putExtra("outputX", 180);
        crop.putExtra("outputY", 180);
        crop.putExtra("aspectX", 3);
        crop.putExtra("aspectY", 4);
        crop.putExtra("scaleUpIfNeeded", true);
        crop.putExtra("return-data", true);
        startActivityForResult(crop, CROP_PIC);

    }
    catch(ActivityNotFoundException e){
        e.printStackTrace();
        Toast.makeText(MainActivity.this, "Error your phone does not support cropping!", Toast.LENGTH_LONG).show();
    }
}

这是我在 onActivityResult 方法

中将图像设置到 imageView 的代码
if(requestCode == CROP_PIC && data != null){
        bitmap = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(bitmap);
    }

图像已设置好,我可以看到它,但按过程出现错误

设置位图时试试这个

if(requestCode == CROP_PIC && data != null){
        bitmap = (Bitmap) data.getExtras().get("data");
        if(bitmap.getConfig() != null){
        imageView.setImageBitmap(bitmap);

    }
 }