Filters and Image Processing
Apply Image Filters
ScanbotSDK.applyImageFilters({ imageFileUri: string, filters: ParametricFilter[] })
Applies filters to an image. As input, a file URI of the image must be passed. The output image will be a new file. The input image file will not be modified.
loading...
Parameters
imageFileUri
- file URI of the image to rotatefilters
- array of ParametricFilter
Returns
Apply Image Filters on Page
ScanbotSDK.applyImageFiltersOnPage({ page: Page, filters: ParametricFilter[] })
Applies an image filter to the hi-res document image of a Page
(documentImageFileUri
) and refreshes the
corresponding preview image (documentPreviewImageFileUri
).
The original, uncropped image of a Page
(originalImageFileUri
) will not be modified.
loading...
Parameters
imageFileUri
- file URI of the image to rotatefilters
- array of ParametricFilter
Returns
Apply Image Filter on Page Result
Supported Image Filters
- ColorDocumentFilter
- ScanbotBinarizationFilter
- CustomBinarizationFilter
- BrightnessFilter
- ContrastFilter
- GrayscaleFilter
- WhiteBlackPointFilter
- LegacyFilter
Page Processing
All SDK components (UI and non-UI) which generate or modify scanned documents use the notion of a Page
as a data model.
A Page object represents a scanned or imported document page.
Pages are stored in an internal page file storage,
where the pageId
serves as a name prefix for the stored image files.
Operations that modify pages work in-place.
That is, for example, rotatePage()
overwrites the page's image files with their rotated versions.
This behavior differs from the behavior of raw image functions like rotateImage()
which always create a new file.
All URI properties of a page have a ?minihash=
query parameter appended to them
with the hash of a portion of the image file.
Different images will almost always have a different hash and therefore a different URI,
which will force the WebView to reload the page's images when changed.
Some file system operations require decoding of the URI before utilization. URI strings are ENCODED by default.
Persistence of Page Objects
Scanbot SDK does not persist page objects, only the image files (.jpg or .png). The management of page objects and the persistence of the page metadata is left to the app. Depending on the use case, it may be necessary to persist the data of the page objects in the app (e.g. as JSON in a local SQLite database). If this is the case, the following must be considered.
The Page objects contain absolute paths to the image files:
{
"pageId": "60426F47-4119-48F8-ADA9-F7E60D583CB4",
"documentPreviewImageFileUri": "file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4_preview.jpg?minihash=a236a8ba5510cd0f4e88bd2045f52c4e",
"originalImageFileUri": "file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/originals/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg?minihash=4e9f0446421343eaaa1e415fdb446a12",
"originalPreviewImageFileUri": "file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/originals/60426F47-4119-48F8-ADA9-F7E60D583CB4_preview.jpg?minihash=da888cd42db07e52b15a6ada29a37b63",
"documentImageFileUri": "file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg?minihash=f9aab62cc37fec555abe94c83406a1b3",
...
}
The page image files are stored in corresponding storage locations - also see the Storage section. By default, the Scanbot SDK Android uses the internal files directory of the app, whereas the Scanbot SDK iOS uses the "Application Support" folder. Those storage folders are secure and are not affected by an app update.
However, on iOS, the absolute file path of the "Application Support" folder is not reliable.
For each fresh install of an app, a new UUID is generated, in the following format:
/var/mobile/Containers/Data/Application/{UUID}
. That is where application data is stored.
When updating the app, the uuid may change. For example:
Before an app update:
file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg
After the app update:
file:///var/mobile/Containers/Data/Application/C9181555-252A-4665-892F-793008ED0EDD/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg
Please note that the actual image files are still there, only the absolute file paths change.
To get the new absolute paths, please use API method refreshImageUris({pages: Page []})
to refresh all image file URIs from affected pages:
import { ScanbotSDK } from 'capacitor-plugin-scanbot-sdk';
// Always make sure you have a valid license on runtime via ScanbotSDK.getLicenseInfo()
if (!(await this.isLicenseValid())) {
return;
}
const result = await ScanbotSDK.refreshImageUris({pages: loadedPages});
const refreshedPages = result.pages;
It is highly recommended using this method whenever you have to (re-)load JSON Page objects from the database of your app, regardless of whether there was an app update or not.
Page Operations
Create Page
ScanbotSDK.createPage(args:{ imageUri: string })
Creates a Page object from an image file (presumably the original image of an uncropped document) and returns the created page object.
As the page has not been cropped yet, the documentImageFileUri
and documentPreviewImageFileUri
properties will be empty.
Set Document Image
ScanbotSDK.setDocumentImage(args:{ page: Page, imageFileUri: string })
Replaces the document image of a page. The passed image file will be copied into the internal page file storage.
Returns the updated page.
Remove Page
ScanbotSDK.removePage(args:{ page: Page })
Removes a page with all its files (original image, document image, thumbnails, filtered images, etc) from the internal file storage.
This method does not remove any export files (PDF, TIFF) which were generated based on this page object.
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.