Skip to main content

Storage for Pages | Android Document Scanner

Many components in the Android Scanbot SDK operate with io.scanbot.sdk.persistence.Page objects as a concept for storing and processing image resources. To make this more flexible for SDK customers, the Scanbot SDK provides an API io.scanbot.sdk.persistence.PageFileStorage to get access to the page content.

val pageFileStorage = ScanbotSDK(context).createPageFileStorage()

Extracting the Page content

PageFileStorage provides methods to extract the original snapped, processed (filtered and cropped) and preview images for the specified Page. As an input these methods need the pageId string value (which can be received from the Page object), PageFileStorage.PageFileType and optionally BitmapFactory.Options, and as a result they return the image android.net.Uri or Bitmap.

Example:

val pageFileStorage = ScanbotSDK(context).createPageFileStorage()

val image: Bitmap? = pageFileStorage.getImage(yourPageId, PageFileStorage.PageFileType.DOCUMENT, BitmapFactory.Options())
// or
val imageUri: Uri = pageFileStorage.getImageURI(yourPageId, PageFileStorage.PageFileType.DOCUMENT)

and the same for the preview images:

val pageFileStorage = ScanbotSDK(context).createPageFileStorage()

val previewImage: Bitmap? = pageFileStorage.getPreviewImage(yourPageId, PageFileStorage.PageFileType.DOCUMENT, BitmapFactory.Options())
// or
val previewImageUri: Uri = pageFileStorage.getPreviewImageURI(yourPageId, PageFileStorage.PageFileType.DOCUMENT)

PageFileStorage.PageFileType enum represents a page image type which corresponds to the some specific image resource:

  • PageFileStorage.PageFileType.ORIGINAL - an original snapped image from the camera
  • PageFileStorage.PageFileType.DOCUMENT - a processed (filtered and cropped) page image
  • PageFileStorage.PageFileType.UNFILTERED_DOCUMENT - a cropped (but not filtered) page image

It is also possible to get all the stored pages - pageFileStorage.getStoredPages(). This returns a list of the ids of all the stored pages.

New Page creation

Users have the ability to create a new Page with an external image (imported from the Gallery or any other sources). PageFileStorage provides methods fun add(image: ByteArray): String and fun add(image: Bitmap): String for this. These methods return a pageId String as a result. Under the hood they create a copy of the input image in the internal SDK files storage structure.

Example:

val pageFileStorage = ScanbotSDK(context).createPageFileStorage()

val newPageId = pageFileStorage.add()
val newPage = Page(newPageId)

There are 2 more methods fun add(image: ByteArray, pageImageSource: PageImageSource): String and fun add(image: Bitmap, pageImageSource: PageImageSource): String which require an additional parameter PageImageSource.

PageImageSource enum represents the source of the image of Page

  • PageImageSource.UNDEFINED - Used by default. If the source is not defined. For example, an image was imported.
  • PageImageSource.MANUAL_SNAP - If the source image was captured manually. For example, when the user pressed a Snap button
  • PageImageSource.AUTOSNAPPING - If the source image was captured automatically. For example, by the auto snapping function
  • PageImageSource.CAMERA_FRAME - If the source image was taken from the camera frame
  • PageImageSource.IMPORT - If the source image was imported from an external source

Page contact modification

PageFileStorage also provides a functionality to replace internal Page images. There are a few methods for this in PageFileStorage:

  • fun setImageForId(image: ByteArray, existingPageId: String, type: PageFileType)
  • fun setImageForId(image: Bitmap, existingPageId: String, type: PageFileType)
  • fun setFilteredPreviewForId(filteredPreview: ByteArray, existingPageId: String, parametricFilter: ParametricFilter)
  • fun setFilteredPreviewForId(filteredPreview: Bitmap, existingPageId: String, parametricFilter: ParametricFilter)
  • fun generateAndSetFilteredPreviewForId(filteredImage: ByteArray, existingPageId: String, parametricFilter: ParametricFilter): Bitmap - returns the generated filtered preview image
  • fun generateAndSetFilteredPreviewForId(filteredImage: Bitmap, existingPageId: String, parametricFilter: ParametricFilter): Bitmap - returns the generated filtered preview image
caution

All existing affected image resources will be replaced.

Page content removing

Page content can be completely removed from the file system:

val pageFileStorage = ScanbotSDK(context).createPageFileStorage()

pageFileStorage.remove(yourPageId)
// or remove all pages
pageFileStorage.removeAll()
Please note

PageFileStorage is not responsible for cleaning up the image files from deleted Page objects.

Instead, you as a Scanbot SDK user should keep track of the Pages that the user no longer needs and clean up their images using one of the methods above.

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?