Resource Base
Table of contents

How to Set a Scan Region

Set a Scan Region

DSRect region = new DSRect();
region.left = 15;
region.right = 85;
region.top = 30;
region.bottom = 70;
region.isMeasuredInPercentage = true;
try {
    mCameraEnhancer.setScanRegion(region);
} catch (CameraEnhancerException e) {
    e.printStackTrace();
}

Add Scan Region Mask & Scan Laser on Camera View

Use the following code to set scan region mask and scan laser.

cameraView.setScanRegionMaskVisible(true);
cameraView.setScanLaserVisible(true);
cameraView.setScanRegionMaskStyle(R.color.scan_region_stroke, R.color.scan_region_mask, 1f);

Remember to add your colours in your res/values/color.xml file.

<resources>
    <color name="scan_region_stroke">#49F549</color>
    <color name="scan_region_mask">#49F5494d</color>
</resources>

Configure your own Scan Region UI

You can either use the CameraView to create the scan region UI or draw it youself.

Since the scan region is set for the video streaming, its coordinate system might not be the same with the view coordinate system. You can use the following code to get the scan region Rect under the view coordinate system:

DSRect region = new DSRect();
region.left = 15;
region.right = 85;
region.top = 30;
region.bottom = 70;
region.isMeasuredInPercentage = true;
try {
    mCameraEnhancer.setScanRegion(region);
} catch (CameraEnhancerException e) {
    e.printStackTrace();
}
// Use mScanRegionRect to set your own scan region UI.
android.graphics.Rect mScanRegionRect = cameraView.convertRectToViewCoordinates(DSRect);

You can disable the default scan region UI with the following code:

cameraView.setScanRegionMaskVisible(false);
cameraView.setScanLaserVisible(false);

This page is compatible for:

Version 1.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest version
    • Version 4.x
      • Version 4.2.0
      • Version 4.0.2
      • Version 4.0.1
      • Version 4.0.0
    • Version 3.x
      • Version 3.0.3
      • Version 3.0.2
      • Version 3.0.1
      • Version 3.0.0
    • Version 2.x
      • Version 2.3.21
      • Version 2.3.20
      • Version 2.3.12
      • Version 2.3.11
      • Version 2.3.10
      • Version 2.3.5
      • Version 2.3.4
      • Version 2.3.3
      • Version 2.3.2
      • Version 2.3.1
      • Version 2.3.0
      • Version 2.1.4
      • Version 2.1.3
      • Version 2.1.1
      • Version 2.0.0
    Change +