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 the properties ScanSettings.ActiveScanningAreaLandscape and ScanSettings.ActiveScanningAreaPortrait or alternatively both can be set to the same value through ScanSettings.SetActiveScanningArea(CGRect). Setting it directly through the orientation-sensitive properties allows 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 new CGRect(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.

ScanSettings settings = ScanSettings.DefaultSettings ();
settings.ActiveScanningAreaPortrait = new CGRect (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 CGRect (0.0, 0.5, 1.0, 0.5);

Careful: CGRect is defined through left and top coordinates as well as a width and height which is different from how the Android RectF is defined.

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.OverlayView.SetViewfinderDimension(0.1, 0.6, 0.1, 0.6); // Be aware that the argument sequence is height/width and not width/height

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 to user to place the code along the laser line.

picker.OverlayView.GuiStyle = GuiStyle.Laser;