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

Switch camera during scanning #110

Open
m1ga opened this issue Mar 17, 2017 · 3 comments
Open

Switch camera during scanning #110

m1ga opened this issue Mar 17, 2017 · 3 comments
Assignees

Comments

@m1ga
Copy link

m1ga commented Mar 17, 2017

When I set my camera to either front or back before starting it the first time like this

if (useFrontCamera){
  mydecoderview.setFrontCamera();
} else {
  mydecoderview.setBackCamera();
}
mydecoderview.setQRDecodingEnabled(true);
mydecoderview.startCamera();

I can set it to either one of them. But when I have the preview running and want to switch the camera with:

mydecoderview.stopCamera();
mydecoderview.setFrontCamera();
mydecoderview.startCamera();

it still uses the old camera direction and the points seem to be flipped (QR code at the bottom -> found dots at the top).

How can I switch cameras during preview?

@qingmei2
Copy link

I also encountered the same problem,waiting for the suggestion.

@qingmei2
Copy link

qingmei2 commented May 4, 2017

My solution,insert code at "QRCodeReaderView.java":

`
public void switchCameraFace() {
releaseCamera();
//"face" means your scanning camera face
face = face == Camera.CameraInfo.CAMERA_FACING_FRONT ? Camera.CameraInfo.CAMERA_FACING_BACK : Camera.CameraInfo.CAMERA_FACING_FRONT;
openCamera(face);
}

private void openCamera(int cameraFace) {
    try {
        mCameraManager.setPreviewCameraId(cameraFace);
        mCameraManager.openDriver(getHolder(), this.getWidth(), this.getHeight());
        mCameraManager.setDisplayOrientation(getCameraDisplayOrientation());
        mCameraManager.startPreview();
        mCameraManager.setPreviewCallback(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void releaseCamera() {
    mCameraManager.setPreviewCallback(null);
    mCameraManager.stopPreview();
    mCameraManager.closeDriver();
}`

and you just need use this code to switch Camera during scanning :
mQRCodeReaderView.switchCameraFace();

@shakour610
Copy link

shakour610 commented May 4, 2017 via email

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

No branches or pull requests

4 participants