Search code examples
androidbarcodezxing

ZXing double image/overlay after scan


I am using the ZXing library, fully integrated with jar files, in my Android app and have the following problem:

Problem:

After scanning a barcode, the scanned image stays on top on the live camera feed at about 50% transparency for about 1-2 seconds.

Question:

Is there any way to have just the scanned image appear at 0% transparency, instead of the strange overlay? Or, even better, can it show a custom fragment?

Thank you.

Code: [w/o unrelated parts]

public static void initiateScan(Fragment fragment) {
    IntentIntegrator ii = new IntentIntegrator(fragment);
    DisplayMetrics dm = fragment.getResources().getDisplayMetrics();
    ii.addExtra("SCAN_WIDTH", dm.heightPixels);
    ii.addExtra("SCAN_HEIGHT", dm.widthPixels / 4);
    ii.addExtra("SCAN_MODE", "ONE_D_MODE");

    List<String> c = new ArrayList<String>();
    c.add("CODE_39");

    ii.initiateScan(c, -1);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==IntentIntegrator.REQUEST_CODE) { // scan from ZXing
        String raw_vin=null;
        String vin = null;
        boolean success=false;

        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, 
                                resultCode, data);
        if(result!=null)
        {
            String content = result.getContents();
            if(content!=null)
            {
                raw_vin=content;
                vin=raw_vin;
                success=true;
            }
        }
    }
}

Example:

Example of double image


Solution

  • Here is what I have in the build.gradle file for dependencies:

    compile 'com.google.zxing:core:3.2.1'
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
    

    Try this in the initiateScan method:

    public static void initiateScan(Fragment fragment) {
        IntentIntegrator ii = IntentIntegrator.forSupportFragment(fragment);
        DisplayMetrics dm = fragment.getResources().getDisplayMetrics();
        ii.addExtra("SCAN_WIDTH", dm.heightPixels);
        ii.addExtra("SCAN_HEIGHT", dm.widthPixels / 4);
        ii.addExtra("SCAN_MODE", "ONE_D_MODE");
        ii.initiateScan(Collections.singletonList("CODE_39"));
    }
    

    Let me know how that works for you.