ZXing start BarcodeScanner portrait layout with IntentIntegrator

I would like to run BarcodeScanner in portrait layout (because my whole application is in portrait layout). I am also wondering if it is possible to install two apps at once from Google Play (you add some kind of dependency in the manifest file to the barcode scanner I use in my app and Google Play automatically installs the barcode scanner along with my app) ...

Thank.

+3


source to share


3 answers


If you need to scan a barcode in Portrait, I would suggest you include the ZXing library in your application and make the appropriate changes to make it work in portrait mode.

Grab the source code here: zxing

You are looking for the android code sample in the library as well as the core.jar file to get the barcode scanned.

For instructions on how to make it work in portrait, follow these steps: Issue 178 - zxing - Launching ZXing in portrait



I would highly recommend reading the thread to get background information on the change, but here's the basics:

  • To make the work on screen in portrait orientation, set the portrait orientation for the action (for example, in the manifest) and then configure the camera: use camera.setDisplayOrientation (90) in CameraConfigurationManager.setDesiredCameraParameters (camera). But keep in mind that:

    • setDisplayOrientation (int) requires Android 2.2
    • setDisplayOrientation (int) does not affect the byte order passed to PreviewCallback.onPreviewFrame. (See JavaDoc for more information)
  • Since the preview frames are always in the "landscape", we need to rotate them. I used the clockwise rotation suggested by the # c11 comment. Don't forget to change the width and height parameters after rotation. DecodeHandler.java, rotate data before buildLuminanceSource to decode (byte [] data, int width, int height)

    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; // Here we are swapping, that the difference to #11
    width = height;
    height = tmp;
    
          

  • I also changed CameraManager.java, getFramingRectInPreview () as recommended # c11:

    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;
    
          

The zxing library is fairly easy to adapt to your application to make it more flexible and integrated. highly recommended.

+2


source


The barcode scanner doesn't support portrait layout, so you won't be able to do that. ( Barcode Scanner + does, but you can't depend on what is installed.) There is no way to force another app to install from the Market, no.



0


source


Hi follow these steps to solve the portrait issue in Zxing barcode scanner which I tried and it works great.

There are 4 relative files:

1, manifest.xml, you need to make CaptureActivity portrait.

      

2, DecodeHandler.java, rotate data before buildLuminanceSource, this works in YCbCr_420_SP and YCbCr_422_SP, Y-channel is flat and appears first

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];
 }

      

3, CameraManager.java, getFramingRectInPreview () needs to be changed.

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;

      

4, CameraConfigurationManager.java, set camera orientation to portrait in setDesiredCameraParameters () use

parameters.set("orientation", "portrait");

      

and in getCameraResolution () you need to swap x and y as the camera preview size is something like 480 * 320 except 320 * 480.

int tmp = cameraResolution.x;
cameraResolution.x = cameraResolution.y;
cameraResolution.y = tmp;
return cameraResolution;

      

0


source







All Articles