Skip to main content

Using EditPolygonImageView | Android Document Scanner

EditPolygonImageView is available with the SDK Package 1. To get started, you have to undertake a few steps.

First: Add it to your layout:


<io.scanbot.sdk.ui.EditPolygonImageView    android:layout_width="match_parent"    android:layout_height="match_parent"    app:edgeColor="#00cea6"    app:cornerImageSrc="@drawable/ui_crop_corner_handle"    app:edgeImageSrc="@drawable/ui_crop_side_handle"    app:editPolygonHandleSize="48dp"    app:magneticLineTreshold="10dp"    app:editPolygonStrokeWidth="3dp"/>

Customizable attributes here are:

  • edgeColor - color of polygon line. Default is undefined meaning - no color.
  • cornerImageSrc - image to be used as polygon corner handle
  • edgeImageSrc - image to be used as edge handle
  • editPolygonHandleSize - Defines touchable area for polygon edge and corner handles. Default is 48dp.
  • editPolygonStrokeWidth - width of polygon line. Default is 3dp.
  • magneticLineTreshold - edge should be this close to magnetic line to snap. Default is 10dp.
  • edgeColorOnLine - color of edge when it aligns detected magnetic line. Default is undefined meaning - no color change.

Default polygon for EditPolygonImageView can be received from ContourDetector. ContourDetector always contains the latest detected contours information like lines and polygons. After the first detection you can set the latest detected contour to EditPolygonImageView.

val detector = ScanbotSDK(context).createContourDetector()detector.detect(image)editPolygonView.polygon = detector.polygonF

Second: EditPolygonImageView supports the magnetic lines feature. For this you have to set the detected horizontal and vertical lines:

editPolygonView.setLines(detector.horizontalLines, detector.verticalLines)

Third: EditPolygonImageView supports the magnifying lens feature. To enable it, you should add io.scanbot.sdk.ui.MagnifierView to your custom layout.

<io.scanbot.sdk.ui.MagnifierView    android:id="@+id/magnifier"    android:layout_width="match_parent"    android:layout_height="match_parent"    app:magnifierImageSrc="@drawable/ui_crop_magnifier"    app:magnifierRadius="36dp"    app:magnifierMargin="16dp"    app:magnifierEnableBounding="true"/>

Customizable attributes here are:

  • magnifierImageSrc - magnifier image. To be used as a mask - make sure it has a transparent section to see the magnified content. No default value.
  • magnifierRadius - magnifier's size. Default is 36dp.
  • magnifierMargin - magnifier's margin - distance to the screen border. Default is 16dp.
  • magnifierEnableBounding - bounce magnifier to opposite part of screen, when editing polygon's corner. Default is true.
Important

You should set up the MagnifierView every time editPolygonView is set with a new image:

magnifierView.setupMagnifier(editPolygonView)

If you want to get a selected polygon from EditPolygonImageView just call:

val currentPolygon = editPolygonView.polygon