Document Scanning SDK for Xamarin.Android
Pixelnetica Document Scanning SDK* (DSSDK) provides developers with an intelligent, highly efficient toolkit, which offers an easy way to add image processing features that are optimized for document photos that are taken by a mobile device or document camera to their applications.
Designed to ensure the smooth operation of a paperless work-flow by pre-processing paper document images, SDK makes them easier to handle by text recognition (or optical character recognition - OCR) programs, enhancing the visual quality and legibility of documents.
For more information about DSSDK main Features and Benefits please visit Pixelnetica website.
*Former Document Imaging SDK
Please feel free to contact us for Free DSSDK Trial, Quotation or in case of any questions.
Prerequisites
- Installed Microsoft Visual Studio with Xamarin Platform
Supported Android versions
- Goggle Android 4.1 (API Level 16) and higher.
Demo Application
To demonstrate most of Document Scanning SDK features and the way how they should be used in real application we prepared demo application available in source codes available by the link below.
⚠️ Important Note.
Demo application source code provided “as is” without warranties of any kind. It could be freely used in commercial product only in case of commercial DSSDK license purchase.
Getting started
Installation
The Document Scanning SDK is provided as NuGet packages for Xamarin Platform.
To install DSSDK in Visual Studio IDE:
- Open your
App-Solution
in Visual Studio. - Select your Android project and click on the menu item
Project
=>Add NuGet Packages
. - Set
nuget.org
as source and search for package ID:Pixelnetica.ImageSdk
. - Click on
Add Package
to download and install the DSSDK into your project.
After following the steps above Document Scanning SDK will be ready to use in your code.
Namespaces
The NuGet packages for Android contain Native SDKs and corresponding Wrappers. The native SDKs and the wrappers are stored in different namespaces which are explained below.
Native SDKs for Android are provided as Xamarin Bindings Libraries and can be found in the following namespaces: Com.Pixelnetica.Docimageproc
and Com.Pixelnetica.Imagesdk
.
Documentation for native DSSDKs classes can be found inside Android Document Scanning SDK documentation .
We recommend to use Xamarin Wrapper namespace ImageSdkWrapper
.
Permissions and Setup
Make sure to add these permissions in your AndroidManifest.xml
file:
-
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
-
android:largeHeap
andandroid:hardwareAccelerated="true"
in<application>
tag:
<application android:label="@string/ApplicationName" android:icon="@drawable/Icon" android:largeHeap="true" android:hardwareAccelerated="true">
-
To use
ImageWriter
object:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
To use
ImageFileWriter
object:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Initialize SDK
The DSSDK must be initialized before usage. Make sure to run the initialization only once per application lifetime.
You can store license key file in application’s Assets folder, e.g.
src/main/assets/pixelnetica/scanning/(file)
Where (file)
is provided by Pixelnetica and can be named as one of following:
- Application package Id with
.key
suffix, e.g.Pixelnetica.SdkDemo.key
- Application package Id, e.g.
Pixelnetica.SdkDemo
license.key
license
key
Add the following code to your Application class:
public class MainApplication : Application
{
public override void OnCreate()
{
ImageSdkLibrary.Load(this);
}
}
⚠️ Important Note.
Document Scanning SDK trial version comes with Trial License Key bound to demo application.
It could also be utilised in other applications for development and testing purpose only where it will generate final images (documents) with watermarks.
It is strictly prohibited to distribute, market, publish to application stores like, but not limited, AppStore, Google Play, etc or use other than for development or staging purposes Pixelnetica Document Scanning SDK trial license.
ImageSdk Modules
Processing
Processing module provides document detection, correction and binarization.
All methods of this module (including creation) must be called in one thread.
Module creation
ImageProcessing sdk = new ImageSdkLibrary().NewProcessingInstance();
Define support image size and scale image if need
Bitmap sourceBitmap = ...; // obtain source bitmap
Point sourceSize = new Point(sourceBitmap.Width, sourceBitmap.Height);
Point supportSize = sdk.SupportImageSize(sourceSize);
Bitmap supportBitmap;
if (sourceSize.Equals(supportSize))
{
// Do not scale
supportBitmap = sourceBitmap;
}
else
{
supportBitmap = Bitmap.CreateScaledBitmap(sourceBitmap, supportSize.X, supportSize.Y, true);
}
Load image metadata using MetaImage object
Most convenient method to load metadata is by using ContentResolver
and image Uri
ContentResolver cr = ...; // obtain Android’s ContentResolver
Uri imageUri = ... // basic Uri
MetaImage sourceImage = new MetaImage(supportBitmap, cr, imageUri);
There are a lot of different methods to create MetaImage
.
Document detection
Bundle args = new Bundle();
Corners corners = sdk.DetectDocumentCorners(originImage, args);
if (args.GetBoolean(ImageSdkLibrary.SdkIsSmartCrop))
{
// Document corners are detected
}
else
{
// Uncertain or bad detection.
// Corners can be null
}
After this you can let user to accept or modify document detection results.
Document cropping and correction
MetaImage croppedImage = sdk.CorrectDocument(sourceImage, corners);
Image processing and binarization
There are 4 available methods for image processing and binarization
-
Binarize to Black and White image.
targetImage = sdk.ImageBWBinarization(croppedImage);
-
Convert to Grayscale image.
targetImage = sdk.ImageGrayBinarization(croppedImage);
-
Enhance image Colors.
targetImage = sdk.ImageColorBinarization(croppedImage);
-
Only rotate image to the right document orientation leaving Original colors untouched.
targetImage = sdk.ImageOriginal(croppedImage);
Termination
All work with ImageProcessing
module must be terminated by calling sdk.Destoy()
or sdk.Close()
.
We recommend using
statement.
using (ImageProcessing sdk = new ImageSdkLibrary().NewProcessingInstance())
{
...
}
ImageWriter module
Module creation
We recommend utilize using
statement to automatically free and destroy writer instance.
using (ImageWriter writer = new ImageSdkLibrary().NewImageWriterInstance(ImageSdkLibrary.ImageWriterPdf))
{
...
}
You can specify a several writer types
-
ImageSdkLibrary.ImageWriterJpeg
to write color JPEG image. -
ImageSdkLibrary.ImageWriterPng
to write color PNG image. -
ImageSdkLibrary.ImageWriterWebM
to write WebM image. -
ImageSdkLibrary.ImageWriterPngExt
to write 1-bit black-and-white PNG image. -
ImageSdkLibrary.ImageWriterPdf
to write a PDF document. -
ImageSdkLibrary.ImageWriterTiff
to write 1-bit Black-and-White TIFF-G4 compressed image. Creates most compact black-and-white files.
Writing images
To write one or several images (or pages) specify image or document file path
writer.Open(filePath);
Also you can specify additional optional parameters specific for current writer type. E.g. compression for JPEG or page size for PDF
writer.Configure(bundle);
Write one image or page. You can call it many times to write multiple pages
writer.Write(image);
For more details we strongly recommend to take a close look at our demo applications source codes.
Still have Questions, need Free Trial or Quotation?
Feel free to contact us in case of any inquires at Pixelnetica DSSDK Support.