Customized camera view & rotation in Zxing for QR code?

后端 未结 3 915
迷失自我
迷失自我 2021-01-12 01:35

I am working with such a great library zxing to read QR code. I already got QR code successfully.

Now, My application runs in landscape mode and camera takes the who

3条回答
  •  礼貌的吻别
    2021-01-12 02:20

    First, please don't copy our app completely. In this case you're going to need to write your own app anyway; it is definitely not as simple as changing the layout orientation. Not only is the UI not written for portrait, but neither is the app code.

    If you want to use only fixed portrait mode, then this is not so hard. Fully supporting all 4 rotations, with front/back cameras, gets hard to get right. But not just 1 case.

    First you need to design a portrait-mode UI. (Don't copy the red-line design please.)

    The actual app code doesn't care about orientation for QR codes. You don't have to do anything there at all. But you do need to make changes to get the screen display right.

    You will need to query Camera.getOrientation() to detect how the camera is mounted. Usually it's such that "up" is to your right, and I think just about every device works this way for compatibility. But technically you need to know so you know how much to rotate the preview image.

    Then you use Camera.setDisplayOrientation() to tell it how much to rotate the image to make it rotated correctly for your portrait mode screen. This is usually "90".

    Finally you need to select the preview size with Camera.Parameters.setPreviewSize() but will possibly need to flip the values you've chosen (480x800 vs 800x480) because you're in portrait.

提交回复
热议问题