Installing the SDK
- Download and run SDTBarcodeSetup.exe
- Follow the Setup Wizard instructions. When asked enter your Developer licnese key or leave the field blank to activate trial license on your computer. The one-time internet connection is required during installation.
- Once setup has finished the folder C:\Program Files\SD-Toolkit\SDTBarcodeSDK will contain runtime components, documentation and sample applications with sourcecode for your reference.
Reading Barcodes from C# Windows Application
The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Samples\SDTBarcodeSampleCSharp.
- Install the SDK.
- In MS Visual Studio Create new C# Windows Application project
- In form design view add button. Set Name property to openFile and Text property to Open File and Read Barcode...
- In form design view add PictureBox. Set Name property to pictureBoxImage. We will use this control to show loaded image.
- In form design view add ListBox. Set Name property to listBoxResults. We will use it for showing recognition results.
- In the solution explorer click right mouse button on Project References and choose Add Reference... Point reference to the SDTBarcode.Net.dll assembly.
- In form design view add openFileDialog.
- In form design view double click on the openFile button. It will add OnButtonClick event handler for button openFile. Modify the openFile_Click handler to be the following:
private void openFile_Click(object sender, EventArgs e) { openFileDialog1.Filter = "All files (*.*)|*.*"; if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { Cursor currentCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; listBoxResults.Items.Clear(); Bitmap imageToShow = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName); //Setup Barcode Engine properties using (SDTBarcode.SDTBarcodeEngine barcodeEngine = new SDTBarcodeEngine("TRIAL")) { barcodeEngine.SetReadInputTypes(SDTBarcodeEngine.SDTBARCODETYPE_ALL_1D); barcodeEngine.SetReadInputDirections(SDTBarcodeEngine.SDTREADDIRECTION_ALL); barcodeEngine.SetActiveScanRectangle(0, 0, imageToShow.Width, imageToShow.Height); Int32 readResult = -1; readResult = barcodeEngine.ReadImageFile(openFileDialog1.FileName, 0); Graphics graph = Graphics.FromImage(imageToShow); if (readResult == 0) { long resultsCount = barcodeEngine.GetResultsCount(); for (Int32 i = 0; i < resultsCount; i++) { string resultValue = barcodeEngine.GetResultValue(i); Int32 resultType = barcodeEngine.GetResultType(i); string resultTypeName = barcodeEngine.GetResultTypeName(i); if (resultValue != null) { if (resultTypeName != null) resultValue += " (" + resultTypeName + ")"; listBoxResults.Items.Add(resultValue); graph.DrawRectangle(new Pen(Color.Red, 3), barcodeEngine.GetResultPositionLeft(i), barcodeEngine.GetResultPositionTop(i), barcodeEngine.GetResultPositionRight(i) - barcodeEngine.GetResultPositionLeft(i), barcodeEngine.GetResultPositionBottom(i) - barcodeEngine.GetResultPositionTop(i)); } } } } this.Cursor = currentCursor; pictureBoxImage.Image = imageToShow; pictureBoxImage.Invalidate(); } }
- Modify Doc properties of the Form controls.
- Build and run the application
Reading Barcodes from C++ Windows Application
The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Samples\SDTBarcodeSampleCpp.
- Install the SDK.
- In MS Visual Studio Create new C++ Windows Console Application project
- Modify newelly created project properties to refer to the SDTBarcode header file and library.
C/C++ -> General-> Additional Include Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Include
Linker -> General ->Additional Library Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDK\lib\x86
Linker -> Input ->Additional Dependencies: SDTBarcode.lib
- Modify stdafx.h to include <windows.h>.
- Initialize BarcodeEngine passing your purchased developer license as a parameter.
void* pReader = SDTCreateBarcodeReaderW(L"License");
- Read the image file
SDTReadImageFileW(pReader, L"C:\\Program Files (x86)\\SD-Toolkit\\SDTBarcodeSDK\\Images\\Ean13.jpg", 0);
- Show results in console
if( SDTGetResultsCount(pReader) > 0 ) { for( int i = 0; i < SDTGetResultsCount(pReader); i++ ) { LPCWSTR value = SDTGetResultValueW(pReader, i); LPCWSTR typeName = SDTGetResultTypeNameW(pReader, i); __int32 type = SDTGetResultType(pReader, i); __int32 direction = SDTGetResultReadDirection(pReader, i); int left = 0, top = 0, right = 0, bottom = 0; left = SDTGetResultPositionLeft(pReader, i); top = SDTGetResultPositionTop(pReader, i); right = SDTGetResultPositionRight(pReader, i); bottom = SDTGetResultPositionBottom(pReader, i); wprintf(L"Found Barcode: %s (%s) at pos:{%d,%d,%d,%d}\n", value, typeName, left, top, right, bottom); } }
- Destroy Barcode Endine
SDTDestroyBarcodeReader(pReader); pReader = NULL;