This package installs ClearImageNet.70.dll assembly, which contains two namespaces.
Inlite.ClearImageNet namespace implements high-level functions recommended to use in new applications. Code examples use only this namespace.
Inlite.ClearImage namespace is substantially compatible with the COM API and is specifically designed to ease the migration from ClearImage COM API applications to .NET. It also supports a few low-level functions.
This example reads code 39 and code 128 barcodes. Set barcode types used in your application. Setting reader.Auto1D=true; automatically finds barcode type, but it is slower and is not recommended for production.
This example reads Postal Barcodes from an image file page.
C#
using Inlite.ClearImageNet;
void ReadPostal_page(string fileName, int page){try{using(BarcodeReader reader =newBarcodeReader()){
reader.FourState =true;// <= Read postal barcodes
Barcode[] barcodes = reader.Read(fileName, page);foreach(Barcode barcode in barcodes){switch(barcode.Type){
case BarcodeType.UspsIntelligentMail:
Console.Write(" US Intelligent Mail");break;
case BarcodeType.BpoPostcode:
Console.Write("UK Royal Mail");break;
case BarcodeType.AustralianPost:
Console.Write("Australian Mail");break;
case BarcodeType.SingaporePost:
Console.Write("Singapore Mail");break;
case BarcodeType.FourState:
Console.Write("ForState ");break;}
Console.WriteLine(" Text: "+ barcode.Text);}}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());}}
Read Driver's License barcode
This example reads the Driver's License barcode from an image file page.
This example reads barcodes from a single-page file or all pages of a multi-page image file.
C#
using Inlite.ClearImageNet;
void ReadBarcode1D_file(string fileName){try{using(BarcodeReader reader =newBarcodeReader()){
reader.Code39 =true; reader.Code128 =true;
Barcode[] barcodes = reader.Read(fileName);// <== Read from all pagesforeach(Barcode barcode in barcodes)
Console.WriteLine($"Barcode type: {barcode.Type} Barcode page: {barcode.Page} Text: {barcode.Text}");}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());}}
Read from a stream
This example reads barcodes from a stream. The stream contains the content of a single image file. For example, if a file is stored in a database.
C#
using Inlite.ClearImageNet;
void ReadBarcode1D_stream(Stream stream){try{using(BarcodeReader reader =newBarcodeReader()){
reader.Code39 =true; reader.Code128 =true;
Barcode[] barcodes = reader.Read(stream);// <== read from a streamforeach(Barcode barcode in barcodes)
Console.WriteLine($"Barcode type: {barcode.Type} Barcode page: {barcode.Page} Text: {barcode.Text}");}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());}}
Image Processing
Repair image page
This example uses some of the most popular image-processing functions. In a production application, the specific sequence of functions should be selected based on specific application needs.
C#
using Inlite.ClearImageNet;
static void RepairPage(ImageEditor editor){
editor.AutoDeskew();
editor.AutoRotate();
editor.AutoCrop(10,10,10,10);// Crop to 10 pixels on each side// editor.AdvancedBinarize(); // Convert to bi-tonal an image with complex background patterns
editor.ToBitonal();
editor.BorderExtract(BorderExtractMode.deskewCrop);// Deskew and crop based on black border
editor.RemovePunchHoles();
editor.SmoothCharacters();
editor.CleanNoise(3);// Clean black noise of 3 pixels// editor.CleanNoise // Clean black and white noise // (CleanNoiseFlags.black | CleanNoiseFlags.white, 3, 3, 10);
editor.ReconstructLines(LineDirection.horzAndVert);}
void Repair_page(string fileName, int page, string fileOut){try{using(ImageEditor editor =newImageEditor()){
editor.Image.Open(fileName, page);// Do image repairRepairPage(editor);// Save results
editor.Image.SaveAs(fileOut, Inlite.ClearImage.EFileFormat.ciEXT);}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());}}
Repair all images in a multi-page file
This example repairs all images in a multi-page file and saves the result in the fileOut file.
C#
using Inlite.ClearImageNet;
private static void _OnEditPage(object sender, EditPageEventArgs e){// e.cancel = true; // Abort file processing // e.skipPage = true; // Remove this page from the outputRepairPage(e.Editor);// See this method in a single page example}
void Repair_file(string fileName, string fileOut){try{using(ImageEditor editor =newImageEditor()){
bool ret = editor.Edit(fileName, _OnEditPage, fileOut, ImageFileFormat.outputFileExtension,true);}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());}}
Repair all images in a stream
This example repairs all images in an input stream and saves the output stream using a specified file format. Streams contain the content of a single image file. For example, if a file is stored in a database.
C#
using Inlite.ClearImageNet;
private static void _OnEditPage(object sender, EditPageEventArgs e){RepairPage(e.Editor);// See this method in a single page example}
Stream Repair_stream(Stream stream, ImageFileFormat output_format){try{using(ImageEditor editor =newImageEditor()){
MemoryStream msOut = editor.Edit(stream, _OnEditPage, output_format);return msOut;}}catch(Exception ex){ Console.WriteLine("Exception: "+ ex.ToString());returnnull;}}