Restricting the Area Where Barcodes are Scanned

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 activeScanningAreaPortrait and activeScanningAreaLandscape on the settings object. The two properties allow you to have different scanning areas dependent on the device orientation. The area itself is specified as a rectangle with coordinates relative to the device's screen size where the top-left corner is 0/0 and the bottom-right corner is 1/1. Setting Scandit.Rect(0.0, 0.0, 1.0, 1.0) would set the scanning area to the entire screen. Following an example of restricting the scanning area to 100% of the screen width and 10% of the screen height centered around the middle of the screen.

var settings = Scandit.ScanSettings();
settings.activeScanningAreaPortrait = new Scandit.Rect(0.0, 0.45, 1.0, 0.1);

Restricting the scanning area to only the bottom half of the screen would look the following way:

settings.activeScanningAreaPortrait = new Scandit.Rect(0.0, 0.5, 1.0, 0.5);


Adjust the viewfinder to match the scanning area

If you reduced the size of the scanning area you likely also want to adjust the size of the viewfinder that guides the user. You can do this by setting the viewfinder dimension on the ScanOverlay. The coordinate system here is the same as when setting the active scanning area, relative to the device's screen going from 0.0 to 1.0.

picker.getOverlayView().setViewfinderDimension(0.6, 0.1, 0.6, 0.1);

Alternatively you can also use the new laser GUI style. This style is mostly for cases where the scanning area is restricted to a relatively low height (around 10% to 20%) as it guides the user to place the code along the laser line.

picker.getOverlayView().setGuiStyle(Scandit.ScanOverlay.GuiStyle.LASER);