简体   繁体   中英

Zxing detects on Android device but not on pc

I am using Zxing core.jar to scan bar codes and qr codes and it's working perfectly, but I want to make tests using Robolectric, to run automated tests without an emulator or device, that will take N number of images through zxing, so my problem is that zxing for some reason is not detecting any type of code format from the .jpg files, I'm not sure if there is a limit size on the image, or something else that I'm missing. The piece of code that does the detection is this, which works fine with frame previews converted to jpgs

        BinaryBitmap bitmap = getBitmapFromImageData(input);
        Collection<BarcodeFormat> decodeFormats = getDecodeFormats();
        Map<DecodeHintType, Object> hints = getHints(decodeFormats);
        MultiFormatReader multiFormatReader = getMultiFormatReader(hints);

        Result rawResult;
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (NotFoundException e) {
            // not really an error, just QR code not found
            Log.e(LOG_TAG, "Code Detection not found exception.");
            return null;
        }

Where the input contains the byte array in jpg format and is being converted by getBitmapFromImageData to Zxings internal formats. And like I said the library is working fine in the device, but I can't find any logical reason on why running this code from my pc won't work.

You're not showing any key code, like how you are reading your image. You should check whether it is being read correctly, being binarized correctly by your code, etc. Look at the unit tests in the project to see how to correctly read and process and image on the desktop. I don't know what your code may be doing in the "get" methods that is different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM