Restrict the scanning area

By default the Scandit Barcode Scanner searches the entire camera feed for barcodes. Under certain conditions it is helpful to restrict the area in which barcodes are recognized, for example if

  • you only show a part of the barcode picker, codes that are not visible should generally not be recognized.
  • there are multiple barcodes close together and the user has to be able to select a specific one.

Restrict the scanning area

Restricting the scanning area is done through setActiveScanningArea(int, RectF) on the settings object. You have to specify an orientation (portrait/landscape) which allows you to have different scanning areas dependent on the device orientation. The area is specified as a rectangle with coordinates relative to the camera preview's size where the top-left corner is 0/0 and the bottom-right corner is 1/1. Setting RectF(left: 0.0f, top: 0.0f, right: 1.0f, bottom: 1.0f) would set the scanning area to the entire camera preview.


The following would set the portrait's scanning area to 90% of the camera preview width and 10% of the preview height (centered).

ScanSettings settings = ScanSettings.create();
settings.setActiveScanningArea(ScanSettings.ORIENTATION_PORTRAIT, new RectF(0.05f, 0.45f, 0.95f, 0.55f));

You can also setup two different scanning areas for wide codes (e.g., EAN13, Code 128) and square codes (e.g., QR, Datamatrix). You can do this with the ScanAreaSettings class.

Careful: RectF is defined through left, top, right, and bottom coordinates which is different from how the iOS CGRect is defined.

Adjust the viewfinder to match the scanning area

The viewFinder is the white rectangle that helps the user to aim for the barcode. If you restricted the scanning area, you most likely want to adjust the viewFinder's size accordingly. You can do this by setting the viewfinder dimension on the ScanOverlay , using as parameters (portraitWidth, portraitHeight, landscapeWidth, landscapeHeight). The coordinate system here is relative to the BarcodePicker 's size.

To adjust the viewFinder's size to the previous example (90% width, 10% height):

mPicker.getOverlayView().setViewfinderDimension(0.9f, 0.1f, 0.9f, 0.1f);

Alternatively, you can use the laser GUI style. It will display a laser line instead of the white rectangle. This style is useful when you want to scan in a small horizontal strip centered on the scanline in the center of the preview as it guides the user to place the code along the laser line.