- ClearImageNet.dll – .NET assembly supports AnyCPU, x86 and x64 development.
- ClearImage.dll – Windows DLL supports COM and JNI entry points. The DLL is distributed as 32-bit version (ClearImage.dll) and 64-bit version (ClearImage.x64.dll). ClearImage COM is registered during the installation process.
The following describes the essential steps of using ClearImage in various programming environments.
.NET API
.NET is a higher level API implemented in the Inlite.ClearImageNet namespace of ClearImageNet.70.
The ClearImageNet assembly also contains a secondary Inlite.ClearImage namespace that 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 that are not accessible through the Inlite.ClearImageNet namespace. Since it mirrors the COM API no additional examples are provided.
To use .NET API add reference to ClearImageNet.70 assembly. Code below demonstrates recommended use of ClearImage .NET API.
C#
12345678910111213141516171819202122232425
using Inlite.ClearImageNet;// . . .void printClearImageInfo(){ Console.WriteLine("ClearImage Server v." + Server.Major.ToString() + "." + Server.Minor.ToString() + "." + Server.Release.ToString() + " " + Server.Edition); Console.WriteLine(Server.GetThreadServer().get_Info(Inlite.ClearImage.EInfoType.ciModulesList, 0));}// . . .void ReadBarcodes1D(string fileName, int page){ BarcodeReader reader = null; try { reader = new BarcodeReader(); // Create and configure reader reader.Code39 = true; reader.Code128 = true; Barcode[] barcodes = reader.Read(fileName, page); // Read barcodes foreach (Barcode barcode in barcodes) // Process results { Console.WriteLine("Barcode type: " + barcode.Type.ToString() + " Text: " + Environment.NewLine + barcode.Text); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.ToString()); } finally { if (reader != null) reader.Dispose(); } // ClearImage 9 and latter. Free image memory.}
VB.NET
1234567891011121314151617181920212223
Imports Inlite.ClearImageNet' . . .Private Sub printClearImageInfo() Console.WriteLine("ClearImage Server v." & Server.Major.ToString() & "." & Server.Minor.ToString() & "." & Server.Release.ToString() & " " & Server.Edition) Console.WriteLine(Server.GetThreadServer().get_Info(Inlite.ClearImage.EInfoType.ciModulesList, 0))End Sub' . . .Private Sub ReadBarcodes1D(ByVal fileName As String, ByVal page As Integer) Dim reader As BarcodeReader = Nothing Try reader = New BarcodeReader() ' Create and configure reader reader.Code39 = True reader.Code128 = True Dim barcodes() As Barcode = reader.Read(fileName, page) ' Read barcodes For Each barcode As Barcode In barcodes ' Process results Console.WriteLine("Barcode type: " & barcode.Type.ToString() & " Text: " & Environment.NewLine & barcode.Text) Next barcode Catch ex As Exception Console.WriteLine("Exception: " & ex.ToString()) Finally If reader IsNot Nothing Then reader.Dispose() ' ClearImage 9 and latter. Free image memory. End Try End Sub
ClearImage installers automatically place ClearImageNet.dll in the GAC. To use it locally (e.g. from executable file folder) remove it from the GAC either from the Inlite Control Center’s Versions tab or by running: gacutil -uf ClearImageNet.70
COM API
This is a lower level API to support development in all languages that can interface to the Windows COM model. Code below demonstrates recommended use of ClearImage COM API.C++
12345678910111213141516171819202122232425262728293031323334353637383940414243
#import "progid:ClearImage.ClearImage" exclude("LONG_PTR") exclude("ULONG_PTR") no_namespace named_guids...int main(int argc, char* argv[]){ CoInitialize(NULL); try { // Initialize COM and ClearImage Server ICiServerPtr Ci; HRESULT hr = Ci.CreateInstance(__uuidof(CiServer)); if (FAILED(hr)) _com_issue_error(hr); // Print version and licensing information cout << "ClearImage COM Version " << Ci->VerMajor << "." << Ci->VerMinor << "." << Ci->VerRelease << endl; cout << Ci->GetInfo(ciModulesList, 0) << endl; // ClearImage API calls, e.g. read barcodes ReadBarcode1D (Ci, "SomeImageFileName", 1); } catch (_com_error e) { printf("_com_error: %s\n", (LPCSTR)e.Description()); } catch (...) { printf("Unknown Exception\n"); } CoUninitialize();}...void ReadBarcode1D(ICiServerPtr& Ci, char* sFileName, int nPage){ ICiBarcodeProPtr reader = NULL; try { reader = Ci->CreateBarcodePro(); reader->Type = (FBarcodeType)(cibfCode128 | cibfCode39); reader->Image->Open(_bstr_t(sFileName), nPage); // Open image reader->Find(0); for (int i = 1; i <= reader->Barcodes->Count; i++) { CiBarcode barcode = reader->Barcodes->Item[i]; cout << "Barcode Type= " << barcode->Type << " Text= " << barcode->Text << endl; } } catch (_com_error& e) { printf("_com_error: %s\n", (LPCSTR)e.Description()); }}
PHP
1234567891011121314151617181920212223242526272829303132
function printClearImageInfo(){ $Ci = new COM("ClearImage.ClearImage"); // Print version and licensing information echo "ClearImage COM Version " . $Ci->VerMajor . "." . $Ci->VerMinor . "." . $Ci->VerRelease . "\n"; echo $Ci->Info(1, 0) . "\n";} function ReadBarcode1D($fileName, $page){ try { // Create ClearImage COM Server $Ci = new COM("ClearImage.ClearImage"); // Creare and configure barcode reader $reader = $Ci->CreateBarcodePro(); $cibfCode39 = 2; $cibfCode128 = 4; $reader->Type = $cibfCode39 + $cibfCode128; // Open image file $reader->Image->Open($fileName, $page); // Read barcodes $BCcount = $reader->Find(0); // Process Results for ($i = 1; $i <= $BCcount; $i++) { $Bc = $reader->BarCodes($i); echo "Barcode Type=" . $Bc->Type . " Text= " . $Bc->Text . "\n"; } } catch(Exception $e) { print "\n" . "Exceptiom in line " . $e->getLine() . "\n" . $e->getMessage() . "\n"; }}
If PHP Fatal error: Class ‘COM’ not found is detected, add this section to php.ini
[PHP_COM_DOTNET] extension=php_com_dotnet.dll fastcgi.impersonate = 0ClearImage exceptions can be recorded in a log file configured through php.ini parameters: ‘log_errors’ and ‘error_log’.
Delphi
- In Project menu select Import Type Library
- Select ClearImage COM Server in list box
- Click on the Create Unit button
For Console (DOS) application:
- Add to uses ActiveX, Windows
- Call CoInitialize(nil); before any ClearImage calls
- Call CoUnInitialize; before exiting the application
1234567891011121314151617181920212223242526272829303132
uses ...,ClearImage_TLB, comobj; // . . . procedure ReadBarcode1D(const fileName: string; const page: integer); var Ci: ICiServer; reader: ICiBarcodePro; i: integer; begin try try begin //Create and configure reader Ci:=CoCiServer.Create; reader:=Ci.CreateBarcodePro; reader.Image.Open(fileName, page); reader.Type_:=cibCode39 or cibCode128; // Read barcodes reader.Find(0); // Process results for i := 1 to reader.Barcodes.Count do begin ShowMessage(reader.Barcodes.Item[i].Text); end; end except on E:Exception do //Process errors ShowMessage(Format('Error:%s.File:%s', [E.Message,FileName])); end finally end end;
VBScript/ASP
1234567891011121314151617181920212223242526
Sub printClearImageInfo() Set Ci = CreateObject("ClearImage.ClearImage") WScript.Echo "ClearImage Server v." & Ci.VerMajor & "." & Ci.VerMinor & "." & Ci.VerRelease & vbCrLf WScript.Echo Ci.Info(1, 0) & vbCrLfEnd Sub Sub ReadBarcode1D(fileName, page) On Error Resume Next 'Create CiServer object: Set Ci = CreateObject("ClearImage.ClearImage") ' Create and configure reader Set reader = Ci.CreateBarcodePro If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub cibfCode39 = 2: cibfCode128 = 4: reader.Type = cibfCode39 + cibfCode128 ' Open Image reader.Image.Open fileName, page If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub ' Read barcodes reader.Find 0 If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub ' Process results For Each Barcode In reader.Barcodes WScript.Echo "Barcode Text= " & Barcode.Text Next End Sub
Multiple versions of ClearImage COM can be installed on the same system. Use Inlite Control Center’s Versions tab to check current version and/or activate different version.
Registration-free COM
Alternatively use this manifest to load ClearImage COM in registration-free COM configuration.
Java API
To use Java API:
- 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 the order of declining 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 variable
- COM registered DLL path, typically displayed in the Inlite Control Center’s Version Tab.
1234567891011121314151617181920212223242526272829303132333435
ICiServer initClearImage() { try { // Create ClearImage Server CiServer objCi = new CiServer(); ICiServer Ci = objCi.getICiServer(); // Display version and licensing information System.out.println("ClearImage ver " + Ci.getVerMajor() + "." + Ci.getVerMinor() + "." + Ci.getVerRelease() + " " + Ci.getInfo(EInfoType.fromInt(6748), 0)); System.out.println(Ci.getInfo(EInfoType.ciModulesList, 0)); return Ci; } catch (Exception ex) { System.out.println(); ex.printStackTrace(); return null; } } void readBarcodes(ICiServer Ci, String fileName, int page) { ICiBarcodePro reader = null; try { reader = Ci.CreateBarcodePro(); // Create and configure barcode reader reader.setType(new FBarcodeType(FBarcodeType.cibfCode39, FBarcodeType.cibfCode128)); reader.getImage().Open(fileName, page); // Open image from an image file int n = reader.Find(0); // Read barcodes for (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) {;} } }