C#
install \<font color="#eb144c">inlite barcodereader ip\</font> nuget packages this package installs \<font color="#eb144c">clearimagenet 70 dll\</font> assembly, which contains two namespaces \<font color="#eb144c">inlite clearimagenet\</font> namespace implements high level functions recommended to use in new applications code examples use only this namespace \<font color="#eb144c">inlite clearimage\</font> 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 clearimage project development use visual studio c# clearimage example project https //barcode reader inliteresearch com/get ci example cs or follow the code examples below extend functionality combine code examples on this page with methods described in clearimage api documentation http //www inliteresearch com/help/ci in developing your project contact support\@inliteresearch com if you have questions exception handling clearimage net api reports errors as an \<font color="#eb144c">exception\</font> object try { // call clearimage net api } catch(exception ex) { console writeline("error " + ex message); } barcode reading read 1d barcodes from a page this example reads code 39 and code 128 barcodes set barcode types used in your application setting \<font color="#eb144c">reader auto1d=true;\</font> automatically finds barcode type, but it is slower and is not recommended for production using inlite clearimagenet; void readbarcode1d page(string filename, int page) { try { using(barcodereader reader = new barcodereader()) { reader code39 = true; reader code128 = true; // reader auto1d = true; barcode\[] barcodes = reader read(filename, page); foreach(barcode barcode in barcodes) console writeline($"barcode type {barcode type} text {barcode text}"); } } catch(exception ex) { console writeline("exception " + ex tostring()); } } read 2d barcode from a page this example reads pdf417, datamatrix, and qr code 2d barcodes might contain binary data available in \<font color="#eb144c">barcode data\</font> property using inlite clearimagenet; void readbarcode2d page(string filename, int page) { try { using(barcodereader reader = new barcodereader()) { reader pdf417 = true; // reader datamatrix = true; // reader qr = true; barcode\[] barcodes = reader read(filename, page); foreach(barcode barcode in barcodes) console writeline($"barcode type {barcode type} text {barcode text}"); } } catch(exception ex) { console writeline("exception " + ex tostring()); } } read postal barcodes from a page this example reads postal barcodes from an image file page using inlite clearimagenet; void readpostal page(string filename, int page) { try { using(barcodereader reader = new barcodereader()) { 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 using inlite clearimagenet; void readdriverlicbarcode page(string filename, int page) { try { using(barcodereader reader = new barcodereader()) { reader drvlicid = true; barcode\[] barcodes = reader read(filename, page); foreach(barcode barcode in barcodes) { inlite data dldecoder decoder = new inlite data dldecoder(); if(decoder decode(text) != "") { console writeline("last " + decoder last); console writeline("first " + decoder first); console writeline("middle " + decoder middle); console writeline("dob " + decoder dob); console writeline("eyes " + decoder eyes); console writeline("hair " + decoder hair); console writeline("sex " + decoder sex); console writeline("height " + decoder height); console writeline("street " + decoder street); console writeline("city " + decoder city); console writeline("state " + decoder state); console writeline("postal " + decoder postal); console writeline("country " + decoder country); console writeline("id " + decoder id); console writeline("issued " + decoder issued); console writeline("expires " + decoder expires); } } } } catch(exception ex) { console writeline("exception " + ex tostring()); } } read from a multi page image file this example reads barcodes from a single page file or all pages of a multi page image file using inlite clearimagenet; void readbarcode1d file(string filename) { try { using(barcodereader reader = new barcodereader()) { reader code39 = true; reader code128 = true; barcode\[] barcodes = reader read(filename); // <== read from all pages foreach(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 using inlite clearimagenet; void readbarcode1d stream(stream stream) { try { using(barcodereader reader = new barcodereader()) { reader code39 = true; reader code128 = true; barcode\[] barcodes = reader read(stream); // <== read from a stream foreach(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()); } } optimize barcode reading this page docid\ smk4 lgrtfex0zacvu2lv describes methods for improving the recognition rate and/or speed 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 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 = new imageeditor()) { editor image open(filename, page); // do image repair repairpage(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 \<font color="#eb144c">fileout\</font> file 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 output repairpage(e editor); // see this method in a single page example } void repair file(string filename, string fileout) { try { using(imageeditor editor = new imageeditor()) { 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 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 = new imageeditor()) { memorystream msout = editor edit(stream, oneditpage, output format); return msout; } } catch(exception ex) { console writeline("exception " + ex tostring()); return null; } }