ImageEn, unit iexHelperFunctions

TIEBitmapHelper.ScanBarcode

TIEBitmapHelper.ScanBarcode


Declaration

function ScanBarcode(): string; overload;
function ScanBarcode(ScanRect: TRect): string; overload;
function ScanBarcode(out BCData: string; out BCType: string; out BCRect: TRect): Integer; overload;
function ScanBarcode(ScanRect: TRect; out BCData: string; out BCType: string; out BCRect: TRect): Integer; overload;


Description

A shortcut method that creates a TIEVisionBarCodeScanner object and calls scan to return the first detected barcode in the image.
You can specify a rect to limit scanning to an area of the image (to speed up processing). Specify Rect(0,0,0,0) to scan the whole image.
First and second overloads return only the barcode data. Third and fouth overloads will also return the barcode type, position and total count of barcodes found.



Note:
You must add the iexHelperFunctions unit to your uses clause
ScanBarcode returns only the first detected barcode. Use TIEVisionBarCodeScanner if you need to find multiple barcodes within an image
Barcode scanning requires IEVision. You will need to register it before calling the method


Method Behaviour

The following call:

count := ImageEnView1.IEBitmap.ScanBarcode( Rect( 0,0,0,0 ), barCodeData, barCodeType, barCodeRect );
if count > 0 then
  ShowMessage( barCodeData + ' (' + barCodeType + ')' );

Is the same as calling:

barCodeSymbols := IEVisionLib.createBarCodeScanner().scan( ImageEnView1.IEBitmap.GetIEVisionImage(), IEVisionRect( 0,0,0,0 ) );
if barCodeSymbols.size() > 0 then
begin
  sym := TIEVisionBarCodeSymbol( barCodeSymbols.getObj(0) );
  ShowMessage( sym.getData().c_str() + ' (' + sym.getSymbolType().c_str() + ')' );
end;


Demo

Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Example

// Detect a barcode in the image

// Get selection (if any)
r := Rect( 0, 0, 0, 0 );
if ImageEnView1.Selected then
  r := IERectangleToRect( ImageEnView1.SelectedRect );

count := ImageEnView1.IEBitmap.ScanBarcode( r, barCodeData, barCodeType, barCodeRect );

if count > 0 then
begin
  s := barCodeData + ' (' + barCodeType + ')';

  ImageEnView1.IEBitmap.IECanvas.Brush.Style := bsClear;
  ImageEnView1.IEBitmap.IECanvas.Pen.Color := Line_Color;
  ImageEnView1.IEBitmap.IECanvas.Pen.Width := Line_Width;
  ImageEnView1.IEBitmap.IECanvas.Rectangle( barCodeRect );

  ImageEnView1.Proc.TextOut( Align_Text_Near_Left, Align_Text_Near_Top, s, 'Arial', Text_Size, Text_Color, [fsBold] );
  ImageEnView1.Update();
end;