Sorry for the delay. A full C++ demo will be available from next release.
The syntax is not as simple as in Delphi:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ievect"
#pragma link "ieview"
#pragma link "imageenview"
#pragma resource "*.dfm"
TMainForm *MainForm;
String FindIEVisionDLLPath()
{
// DEMO CODE ONLY
// The IEVision.DLL may not be located in the EXE folder, so check other common locations
String sExePath = IncludeTrailingBackslash(ExtractFilePath(Application->ExeName));
// In same folder as EXE?
String Result = sExePath + IEVISION_32BIT_DLL_FILENAME1;
if (FileExists(Result))
return Result;
// In Registered version folder?
Result = sExePath + "..\\..\\..\\Registered\\" + IEVISION_32BIT_DLL_FILENAME1;
if (FileExists(Result))
return Result;
// In trial version folder?
Result = sExePath + "..\\..\\..\\Trial\\" + IEVISION_32BIT_DLL_FILENAME1;
if (FileExists(Result))
return Result;
// In parent folder of EXE?
Result = sExePath + "..\\" + IEVISION_32BIT_DLL_FILENAME1;
if (FileExists(Result))
return Result;
// Or its parent?
Result = sExePath + "..\\..\\" + IEVISION_32BIT_DLL_FILENAME1;
if (FileExists(Result))
return Result;
return ""; // Not found, try system path
}
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
// Calling IEInitialize_ievision is NOT required if the IEVision DLL is located in the same folder as the EXE or on the system path
// You need only call IEVisionAvailable which will automatically call IEInitialize_ievision
String sDLLPath = FindIEVisionDLLPath();
if (sDLLPath != "")
IEInitialize_ievision(sDLLPath, false); // Initialize DLL in custom location
if (!IEVisionAvailable()) {
ShowMessage("This application requires the ievision.dll plugin. Please download it from www.imageen.com");
Application->Terminate();
}
}
//---------------------------------------------------------------------------
// Open
void __fastcall TMainForm::ButtonOpenClick(TObject *Sender)
{
String filename = ImageEnVect1->IO->ExecuteOpenDialog();
if (filename != "")
LoadImage(filename);
}
//---------------------------------------------------------------------------
// Load a barcode image
void TMainForm::LoadImage(const String sFilename)
{
// load file
ImageEnVect1->RemoveAllObjects();
ImageEnVect1->DeSelect();
ImageEnVect1->IO->LoadFromFile(sFilename);
ImageEnVect1->Fit();
TrackBar1->Position = int(ImageEnVect1->Zoom);
}
//---------------------------------------------------------------------------
// Zoom
void __fastcall TMainForm::TrackBar1Change(TObject *Sender)
{
ImageEnVect1->Zoom = TrackBar1->Position;
}
//---------------------------------------------------------------------------
// Detect
void __fastcall TMainForm::ButtonDetectClick(TObject *Sender)
{
try {
TreeViewResults->Items->Clear();
ImageEnVect1->SelectionBase = iesbBitmap;
TIEVisionRect selRect = IEVisionRect(0, 0, 0, 0);
if (ImageEnVect1->Selected)
selRect = IEVisionRect(ImageEnVect1->SelX1,
ImageEnVect1->SelY1,
ImageEnVect1->SelX2 - ImageEnVect1->SelX1 + 1,
ImageEnVect1->SelY2 - ImageEnVect1->SelY1 + 1);
// create bar code scanner object
_di_TIEVisionBarCodeScanner barCodeScanner;
IEVisionLib()->createBarCodeScanner(false, barCodeScanner);
// run bar code scanner
barCodeScanner->scan(ImageEnVect1->IEBitmap->GetIEVisionImage(), selRect, false, m_symbols);
// get number of found symbols
int symbolsCount;
m_symbols->size(true, symbolsCount);
// iterate among found symbols
for (int i = 0; i < symbolsCount; i++) {
// get "i" symbol (as generic TIEVisionBase interface)
_di_TIEVisionBase bs;
m_symbols->getObj(i, false, bs);
// cast symbol to TIEVisionBarCodeSymbol interface
_di_TIEVisionBarCodeSymbol s = static_cast<TIEVisionBarCodeSymbol*>(&*bs);
// create a new tree child node using the symbol index
TTreeNode* n = TreeViewResults->Items->AddChild(NULL, IntToStr(i));
// get symbol type as IEVision string
_di_TIEVisionWString st;
s->getSymbolType(false, st);
// convert IEVision string to C string
WideChar* wch;
st->c_str(false, wch);
// create a new tree child node using the symbol type C string
TreeViewResults->Items->AddChild(n, wch);
// get symbol data as IEVision string
_di_TIEVisionWString dt;
s->getData(false, dt);
// convert IEVision string to C string
dt->c_str(false, wch);
// create a new tree child node using the symbol data C string
TreeViewResults->Items->AddChild(n, wch);
}
TreeViewResults->FullExpand();
}
catch(const Exception& e) {
if (dynamic_cast<EAccessViolation const*>(&e))
ShowMessage("An error was encountered processing this image. Ensure you are using the latest version of the IEVision plug-in.");
else
ShowMessage("An error was encountered processing this image: " + e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::TreeViewResultsChange(TObject *Sender, TTreeNode *Node)
{
while (Node->Parent)
Node = Node->Parent;
ImageEnVect1->RemoveAllObjects();
// get symbol for the selected tree node (convert tree node text to int, representing the symbol index)
_di_TIEVisionBase obj;
m_symbols->getObj(StrToInt(Node->Text), false, obj);
// convert TIEVisionBase interface to TIEVisionBarCodeSymbol interface (to use getBoundingBox method)
_di_TIEVisionBarCodeSymbol sym = static_cast<TIEVisionBarCodeSymbol*>(&*obj);
// get IEVision rectangle for the symbol
TIEVisionRect rect;
sym->getBoundingBox(false, rect);
// create a TImageEnVect box which highlight the symbol bounding box
ImageEnVect1->ObjKind[-1] = iekBOX;
ImageEnVect1->ObjLeft[-1] = rect.x;
ImageEnVect1->ObjTop[-1] = rect.y;
ImageEnVect1->ObjWidth[-1] = rect.width;
ImageEnVect1->ObjHeight[-1] = rect.height;
ImageEnVect1->ObjBoxHighlight[-1] = true;
ImageEnVect1->ObjBrushColor[-1] = clYellow;
ImageEnVect1->AddNewObject();
}
//---------------------------------------------------------------------------