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
ICiServer initClearImage(){try{
CiServer.loadClearImage("C:\\Program Files (x86)\\Inlite\\ClearImageSDK\\x64\\ClearImage.dll");// Create ClearImage Server
CiServer objServer =newCiServer();
ICiServer Server = onjServer.getICiServer();return Server;}catch(Exception ex){
System.out.println(ex.getMessage());returnnull;}}
void readBarcodes(ICiServer Ci, 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 file
int n = reader.Find(0);// Read barcodesfor(int i =1; i <= n; i++){// Process results
ICiBarcode Bc = reader.getBarcodes().getItem(i);// getItem is 1-based
System.out.println(" Barcode + type: "+ Bc.getType()+" Text: \n"+ Bc.getText());}}catch(Exception ex){// Process exceptions
System.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
void ReadBarcode1D_page(ICiServer Server, 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++){
ICiBarcode Bc = 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[]
Java
void ReadBarcode2D_page(ICiServer Server, String fileName, int page){try{
ICiQR reader = Server.CreateQR();// ICiPdf417 reader = Server.CreatePdf417();// ICiDataMatrix reader = Server.CreateDataMatrix();
reader.getImage().Open(fileName, page);
reader.Find(0);for(int i =1; i <= reader.getBarcodes().getCount(); i++){
ICiBarcode Bc = reader.getBarcodes().getItem(i);
System.out.println(Bc.getText());}}catch(Exception ex){
System.out.println(ex.getMessage());}finally{
System.gc();}}
Read Postal Barcodes from a page
This example reads Postal Barcodes from an image file page.
Java
void ReadBarcodePostal_page(ICiServer Server, 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++){
ICiBarcode Bc = 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 reads barcodes from a single page or all pages of a multi-page image file.
Java
void ReadBarcode1D_page(ICiServer Server, String fileName, int page){try{
ICiBarcodePro reader = Server.CreateBarcodePro();
reader.setType(newFBarcodeType(FBarcodeType.cibfCode39,
FBarcodeType.cibfCode128));
int page =1;while(true){
reader.getImage().Open(fileName, page);
reader.Find(0);for(int i =1; i <= reader.getBarcodes().getCount(); i++){
ICiBarcode Bc = reader.getBarcodes().getItem(i);
System.out.println(Bc.getText());}
page++;if(page > reader.getImage().getPageCount())break;}}catch(Exception ex){
System.out.println(ex.getMessage());}finally{
System.gc();}}
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.
Java
void RepairPage (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 border
repair.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);}
void Repair_page(ICiServer Server, 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.