Add ClearImageJ.jar to CLASSPATH. Typically file is located in C:\Program Files (x86)\Inlite\Libs folder.
Java API uses several methods to locate ClearImage.dll listed below in descending priority.
Explicit path using the CiServer.loadClearImage(ClearImageDllPath) method.
Folder specified by -Djava.library.path="ClearImageDllPath" on the java command line.
Folders specified by the PATH environmental variable
Use the correct 32-bit or 64-bit version of ClearImage.dll, that matches your Java runtime version. ClearImage.dll is located in subfolder of C:\Program Files (x86)\Inlite\ClearImageSDK folder \win32 and \x64
This code demonstrates the use of ClearImage Java API. Runtime errors are reported in Exception object.
Java
ICiServerinitClearImage(){try{CiServer.loadClearImage("C:\\Program Files (x86)\\Inlite\\ClearImageSDK\\x64\\ClearImage.dll");// Create ClearImage ServerCiServer objServer =newCiServer();ICiServerServer= onjServer.getICiServer();returnServer;}catch(Exception ex){System.out.println(ex.getMessage());returnnull;}}voidreadBarcodes(ICiServerCi,String fileName,int page){ICiBarcodePro reader =null;try{
reader =Ci.CreateBarcodePro();// Create and configure barcode reader
reader.setType(newFBarcodeType(FBarcodeType.cibfCode39,FBarcodeType.cibfCode128));
reader.getImage().Open(fileName, page);// Open image from an image fileint n =reader.Find(0);// Read barcodesfor(int i =1; i <= n; i++){// Process resultsICiBarcodeBc= reader.getBarcodes().getItem(i);// getItem is 1-basedSystem.out.println(" Barcode + type: "+Bc.getType()+" Text: \n"+Bc.getText());}}catch(Exception ex){// Process exceptionsSystem.out.println(); ex.printStackTrace();}finally{if(reader !=null)try{
reader.getImage().Close();// Close images and free memory}catch(Exception ex){;}}}
ClearImage project development
Extend functionality
While developing your application, you can combine code examples on this page with methods described in ClearImage API documentation.
Exception handling
ClearImage Java API reports errors as an Exceptionobject.
This example reads code 39 and code 128 barcodes. Set barcode types used in your application. Setting reader.setAutoDetect1D(EBoolean.ciTrue); automatically finds the barcode type, but it is slower and is not recommended for production.
Java
voidReadBarcode1D_page(ICiServerServer,String fileName,int page){try{ICiBarcodePro reader =Server.CreateBarcodePro();
reader.setType(newFBarcodeType(FBarcodeType.cibfCode39,FBarcodeType.cibfCode128));// readerbcr.setAutoDetect1D(EBoolean.ciTrue);
reader.getImage().Open(fileName, page);reader.Find(0);for(int i =1; i <= reader.getBarcodes().getCount(); i++){ICiBarcodeBc= reader.getBarcodes().getItem(i);System.out.println(Bc.getText());}}catch(Exception ex){System.out.println(ex.getMessage());}finally{System.gc();}}
Read 2D Barcode from a page
This example reads PDF417, DataMatrix, and QR code. 2D barcodes might contain binary data available from Bc.getData() as byte[]
This example reads Postal Barcodes from an image file page.
Java
voidReadBarcodePostal_page(ICiServerServer,String fileName,int page){try{ICiBarcodePro reader =Server.CreateBarcodePro();
reader.setType(newFBarcodeType(FBarcodeType.cibf4State));
reader.getImage().Open(fileName, page);reader.Find(0);for(int i =1; i <= reader.getBarcodes().getCount(); i++){ICiBarcodeBc= reader.getBarcodes().getItem(i);EBarcodeType type =Bc.getType();if(type ==EBarcodeType.cibUspsIntelligentMail)System.out.println(" US Intelligent Mail ");if(type ==EBarcodeType.cibBpoPostcode)System.out.println("UK Royal Mail ");if(type ==EBarcodeType.cibAustralianPost)System.out.println("Australian Mail ");if(type ==EBarcodeType.cibSingaporePost)System.out.println("Singapore Mail ");System.out.println(Bc.getText());}}catch(Exception ex){System.out.println(ex.getMessage());}finally{System.gc();}}
Read Driver's License barcode
This example reads the Driver's License barcode from an image file 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.
Java
voidRepairPage(ICiRepair repair){repair.AutoDeskew();repair.AutoRotate();repair.AutoCrop(10,10,10,10);repair.AdvancedBinarize(0,0,0);repair.BorderExtract(EBorderExtractFlags.ciBexBorderDeskewCrop,EBorderExtractAlgorithm.ciBeaCleaner);// Deskew and crop based on black borderrepair.RemovePunchHoles();repair.SmoothCharacters(ESmoothType.ciSmoothDarkenEdges);repair.CleanNoise(3);// Clean black noise of 3 pixels// repair.CleanNoiseExt // Clean black and white noise// (new ECleanNoiseFlags(ECleanNoiseFlags.ciCnxBlackNoise, ECleanNoiseFlags.ciCnxWhiteNoise), 3, 3, 10, 0); repair.ReconstructLines(ELineDirection.ciLineVertAndHorz);}voidRepair_page(ICiServerServer,String fileName,int page,String fileOut){try{ICiRepair repair =Server.CreateRepair();
repair.getImage().Open (fileName, page);RepairPage(repair);
repair.getImage().SaveAs(fileOut,EFileFormat.ciEXT);}catch(Exception ex){System.out.println(ex.getMessage());}finally{System.gc();}}
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.