Android Zxing change orientation to portrait

Udi Idan picture Udi Idan · Apr 18, 2012 · Viewed 37.8k times · Source

I'm trying to rotate Zxing display after reading a few questions and posts about the issue. After following the instructions, the display did rotate, but the rectangle of the scanner is not positioned as it should (as can be seen on the image attached).

This is what I have done:

  1. in CameraConfigurationManager:

    camera.setDisplayOrientation(90);
    
  2. in DecodeHandler.java

    byte[] rotatedData = new byte[data.length];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++)
                 rotatedData[x * height + height - y - 1] = data[x + y * width];
         }
    int tmp = width;         
    width = height;
    height = tmp;
    
  3. in CameraManager.java:

    rect.left = rect.left * cameraResolution.y / screenResolution.x;
    rect.right = rect.right * cameraResolution.y / screenResolution.x;
    rect.top = rect.top * cameraResolution.x / screenResolution.y;
    rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
    

enter image description here

Answer

Udi Idan picture Udi Idan · Apr 19, 2012

After a lot of struggling, I found the problem, and I hope it will help someone in the future.

On initFromCameraParameters method in CameraConfigurationManager there is an assumption that the scan is ALWAYS in landscape mode, and therefor a fix when width < height. If You follow the steps in the question and remove this check, it works fine.