Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor sharpness on iPhone Pro #535

Open
wirthti opened this issue Sep 11, 2023 · 1 comment
Open

Poor sharpness on iPhone Pro #535

wirthti opened this issue Sep 11, 2023 · 1 comment
Labels

Comments

@wirthti
Copy link

wirthti commented Sep 11, 2023

Hi!

I had an issue where the sharpness of the image was really poor on the newest iPhone (13 and up). I fixed it by adding this to my code, overriding the behaviour of some components:

ZXingScannerComponent.prototype.getAnyVideoDevice = (): Promise<MediaStream> => {
            return navigator.mediaDevices.getUserMedia({
                audio: false,
                video: {
                    width: { min: 640, ideal: 1920 },
                    height: { min: 400, ideal: 1080 },
                    aspectRatio: { ideal: 1.7777777778 }
                }
            });
        };


       BrowserCodeReader.prototype.decodeFromVideoDevice = async function(
            deviceId: string | undefined,
            previewElem: string | HTMLVideoElement | undefined,
            callbackFn: any,
        ): Promise<IScannerControls> {
            // We had to comment this out because it is a private method...
            // BrowserCodeReader.checkCallbackFnOrThrow(callbackFn);

            let videoConstraints: MediaTrackConstraints;

            if (!deviceId) {
                videoConstraints = { facingMode: 'environment' };
            } else {
                videoConstraints = {
                    deviceId: { exact: deviceId },
                    width: { min: 640, ideal: 1920 },
                    height: { min: 400, ideal: 1080 },
                    aspectRatio: { ideal: 1.7777777778 }
                };
            }

            const constraints: MediaStreamConstraints = { video: videoConstraints };

            return await this.decodeFromConstraints(constraints, previewElem, callbackFn);
        }

This forces the camera to use full HD resolution. The problem is, when used in iPhones with 3 back cameras, where one of them is specifically used for close up pictures, it does not work. The image is blurry, because it does not automatically change to this camera. The main camera in those iPhones is not projected for close up pictures, so the image when trying to read a barcode is very blurry, so it doesn't work.

Is there any way to force the phone to use this special close up camera when present?

@wirthti wirthti added the bug label Sep 11, 2023
@jaiminpatelmicrotech
Copy link

not so sure just give it a try may be it works for you it did for me

just decrease the values

width: { min: 640, ideal: 1080},
height: { min: 400, ideal: 480},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants