ZXing not scanning on larger resolutions

We have an app that isn't finding (or really struggling to find) QR Codes one so far these confirmed devices:
Nexus 7 tablet 2013
Samsung S4
Samsung S5

Basically it rarely finds the code unless it is a long way from the device so that it occupies a very small part of screen real estate.

It appears that it might be something to do with the viewfinder and I've read that this is by design but it seems primarily functional design not usability-centered design! Our app has a custom overlay with a custom 'scope' that scales with the screen size. It's far prettier to scale it instead of having this really tiny screen in the very center. Besides we have other UI elements directly related to the size of the scope which should not be that tiny if the device is large!

Any help greatly appreciated! Struggling here... :(

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    I've used it on a Note 3 (Full HD, 5.7" screen) before, which worked fine. There has been some improvements to the speed of the component, but that was some while ago. Where do you get the ZXing? From the component store? GitHub? Not sure whether they are the same version. I know the version from GitHub works fine.

    How big are your QR codes?

  • Le-royStaines.7824Le-royStaines.7824 NZMember ✭✭✭

    Hmm. OK might have to try the latest in case it's just the old version. I was hoping I wouldn't have to do that!

    Physically: 4cm x 4cm
    Modules/Data size: 25 x 25 modules

  • Le-royStaines.7824Le-royStaines.7824 NZMember ✭✭✭
    edited August 2014

    EDIT: Downloaded the sample of the latest version. Still having issues. Namely on the fragment version; I can get it to detect a QR code just fine except it freezes at that point. Or at least does not resume scanning. Our app requires continuous scanning :(

  • Le-royStaines.7824Le-royStaines.7824 NZMember ✭✭✭

    Solved!

    It was to do with the camera preview size. The default preview size was 1920 x 1200 but when I changed it to 1280 x 768 it worked much better! IMPORTANT: Do not hard-code that value as not all devices will support it. To determine the 'best fit' here's what I have so far (and I suspect I need to fine tune it some more but it is a start)...

                public void SurfaceChanged (ISurfaceHolder holder, global::Android.Graphics.Format format, int w, int h)
                {
                    if (camera == null)
                        return;
    
                    Camera.Parameters parameters = camera.GetParameters ();
    
                    width = w;
                    height = h;
    
                    IList<Camera.Size> sizes;
                    Camera.Size selectedPreviewSize;
                    sizes = parameters.SupportedPreviewSizes;
                    if (sizes != null) {
                        selectedPreviewSize = sizes.Where(a=> a.Width > 640).OrderBy (a => a.Height).FirstOrDefault (); //GetOptimalPreviewSize (sizes, width, height);
                        if (selectedPreviewSize != null) {
                            parameters.SetPreviewSize (selectedPreviewSize.Width, selectedPreviewSize.Height);
                            width = selectedPreviewSize.Width;
                            height = selectedPreviewSize.Height;
                        }
                    }
    
                    camera.SetParameters (parameters);
                    try {
                        camera.SetDisplayOrientation (90);
                    } catch {
                    }
                    camera.StartPreview ();
                    try {
                        camera.AutoFocus (this);
                    } catch {
                    }
                    /*
                    try {
                        this.SetCameraDistance(2.7f);
                        QrScannerActivity.canSetCameraDistance = true;
                    } catch {
                        QrScannerActivity.canSetCameraDistance = false;
                    }*/
    
                }
    
  • I am also using ZXing bar code scanner. I have used the component sample code. That does support multiple type bar code fonts and flash light, but i want to change camera preview like 800x600. Is this possible to change camera resolution and other things in code?

  • Le-royStaines.7824Le-royStaines.7824 NZMember ✭✭✭

    Yes it is but I believe it has to be a size the your device supports. Look at my sample code above, around the area:

                    Camera.Parameters parameters = camera.GetParameters ();
    
                    width = w;
                    height = h;
    
                    IList<Camera.Size> sizes;
                    Camera.Size selectedPreviewSize;
                    sizes = parameters.SupportedPreviewSizes;
                    if (sizes != null) {
                        selectedPreviewSize = sizes.Where(a=> a.Width > 640).OrderBy (a => a.Height).FirstOrDefault (); //GetOptimalPreviewSize (sizes, width, height);
                        if (selectedPreviewSize != null) {
                            parameters.SetPreviewSize (selectedPreviewSize.Width, selectedPreviewSize.Height);
                            width = selectedPreviewSize.Width;
                            height = selectedPreviewSize.Height;
                        }
                    }
    
                    camera.SetParameters (parameters);
    

    You should be able to make enough sense of that to figure out what you want to do. You may not be able to achieve 800x600 exactly but you could find the closest supported size at runtime and choose that one.

Sign In or Register to comment.