Skip to main content
Version: 3.10

Examples

Set new Region of interest with new Camera orientation

This example can be used to scan BVR in a portrait application (the must be put in landscape).

Display display = getActivity().getWindowManager().getDefaultDisplay();
int stageWidth = display.getWidth();
int stageHeight = display.getHeight();
int width = stageWidth, height = stageHeight;
if(width > height)
// Set new ROI
mSmartScanner.setRegionOfInterest(new Rect(height / 100 * 15,width / 10 ,width / 100 * 95,height / 100 * 80));
else {
/**
* Set the new orientation decoding on the device. By activating this mode you must manage the ROI manually.
* @param forceOrientationEnabled true if the decoder should decode in manual orientation
* @param scanOrientation the orientation for decoding.The options are: LANDSCAPE_MODE, LANDSCAPE_REVERSE_MODE, PORTRAIT_MODE, PORTRAIT_REVERSE_MODE
*
*/
mSmartScanner.setOrientationDecoding(true, SmartScanner.LANDSCAPE_MODE);
mSmartScanner.setRegionOfInterest(new Rect(height / 100 * 10, width / 100 * 15, width / 100 * 85, height / 100 * 90));
}

Flash

Enable/disable the flash with a toggle button

...
someToggleButton.setOnCheckedChangeListener(flashModeLister);
...

private CompoundButton.OnCheckedChangeListener flashModeLister = new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
mSmartScanner.setFlashEnabled(true);
else
mSmartScanner.setFlashEnabled(false);
}
};

Enable/disable Auto-Focus

Enable/disable the Auto-Focus with a toggle button

...
someToggleButton.setOnCheckedChangeListener(focusModeLister);
...

private CompoundButton.OnCheckedChangeListener focusModeLister = new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
mSmartScanner.setAutoFocusEnabled(true);
else
mSmartScanner.setAutoFocusEnabled(false);
}
};


Manual focus

On main layout put the focus view

<View
android:id="@+id/focus"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
android:background="@drawable/rectangle" />

Add to drawable folder the new shape

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#00000000" />

<stroke
android:width="1dp"
android:color="#8BC34A" />

<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />

</shape>
/**
* On double tap we switch to manual focus. We try focusing on the region were the double tap was done.
* @param x Position on x axis on the screen
* @param y Position on y axis on the screen
* @param view View where we will draw the focus rectangle
* @param isFocusRectangleVisible Option to draw the focus rectangle or not
*/

mSmartScanner.manualFocus(mPrimStartTouchEventX, mPrimStartTouchEventY, root.findViewById(R.id.focus), true);

Enable disable hight resolution

Enable/disable the resolution with a toggle button

...
someToggleButton.setOnCheckedChangeListener(focusModeLister);
...

private CompoundButton.OnCheckedChangeListener focusModeLister = new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
mSmartScanner.setHighResolution(true);
else
mSmartScanner.setHighResolution(false);
}
};


Save picture

Add a view to display the image

<ImageView
android:id="@+id/picture_view"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_gravity="center"/>
</LinearLayout>

Implement the OnSavedPictureReadyListener listener

mSmartScanner.setOnSavedPictureReadyListener(pictureBytes -> {
if (pictureBytes != null) {
Bitmap bmp = BitmapFactory.decodeByteArray(pictureBytes, 0, pictureBytes.length);
((ImageView) findViewById(R.id.picture_view)).setImageBitmap(bmp);
}
});

Trigger a capture with the following function

/**
* Take a picture of the scanning process
* @param onlyROI Set the area of the picture capture
*/
mSmartScanner.savePicture(onlyRoi)

or enable automatic capture when the image is successfully decoded

/**
* If enabled, each successfully decoded image is saved and returned via the OnSavedPictureReadyListener listener
* @param enabled Set the state of the returned image
* @param onlyROI Set the area of the picture capture
*/
mSmartScanner.setOnLoadedListener(roi -> {
mSmartScanner.setSaveDecodedPictureEnabled(enabled, onlyRoi);
});