Leadtools.Barcode名前空間 > BarcodeReaderクラス :再増シンボルイベント |
public event EventHandler<BarcodeReadSymbologyEventArgs> ReadSymbology
'Declaration
Public Event ReadSymbology As EventHandler(Of BarcodeReadSymbologyEventArgs)
'Usage
Dim instance As BarcodeReader Dim handler As EventHandler(Of BarcodeReadSymbologyEventArgs) AddHandler instance.ReadSymbology, handler
public event EventHandler<BarcodeReadSymbologyEventArgs> ReadSymbology
@property (nonatomic, weak, nullable) id<LTReadSymbologyDelegate> delegate
public void addReadSymbologyListener(BarcodeReadSymbologyListener listener) public void removeReadSymbologyListener(BarcodeReadSymbologyListener listener)
add_ReadSymbology(function(sender, e)) remove_ReadSymbology(function(sender, e))
public: event EventHandler<BarcodeReadSymbologyEventArgs^>^ ReadSymbology
イベントハンドラは、このイベントに関連するデータを格納するタイプBarcodeReadSymbologyEventArgsの引数を受け取ります。以下のBarcodeReadSymbologyEventArgsプロパティは、このイベントに特有の情報を提供します。
プロパティ | 説明 |
---|---|
Data | 見つかったバーコードデータを取得します。 ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Error | 読み取り操作中に発生したエラー。 ![]() ![]() ![]() ![]() ![]() |
HResult | 読み取り操作中に発生したエラー。 ![]() ![]() ![]() |
Operation | 現在のバーコード読込み操作を取得します。 ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Options | バーコード体系を読むのに用いられているオプションを取得します。 ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Options | このメソッドに関する詳細は、オプションを参照してください。 ![]() ![]() |
Status | 読込み操作のステータスを取得または設定します。 ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
SymbologiesCount | バーコード体系のカウントを取得します。 ![]() ![]() |
情報を得て、現在のバーコード読込み操作のステータスを設定するために、ReadSymbologyイベントを使います。
BarcodeReader.ReadBarcodeまたはBarcodeReader.ReadBarcodesを使用してバーコードを読み取るとき、BarcodeReaderオブジェクトは、読み取られるバーコード体系に応じてReadSymbologyイベントを複数回発生させます。
LEADTOOLSのバーコード読み取りは速度を優先して設計されています。バーコードが類似した特徴を持つときは1回の操作で複数のバーコード体系を読み取る(または検索する)ことができます。したがって、読まれているバーコード体系は、BarcodeSymbology配列で保存されて、BarcodeReadSymbologyEventArgs.GetSymbologiesメソッドで得られます。
以下のテーブルは、イベントメンバと意味をリストします:
このサンプルは、バーコード読み取りのカレントステータスを取得するためにReadSymbologyを使う方法を示します。
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Public Sub BarcodeReader_ReadSymbologyExample() Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif") ' Create a Barcode engine Dim engine As New BarcodeEngine() ' Get the Barcode reader instance Dim reader As BarcodeReader = engine.Reader ' Load the image Using codecs As New RasterCodecs() Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1) ' Subscribe to the ReadSymbology event AddHandler reader.ReadSymbology, AddressOf reader_ReadSymbology ' Read all barcodes in the image reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing) RemoveHandler reader.ReadSymbology, AddressOf reader_ReadSymbology End Using End Using End Sub Private Sub reader_ReadSymbology(ByVal sender As Object, ByVal e As BarcodeReadSymbologyEventArgs) If e.Operation = BarcodeReadSymbologyOperation.PreRead Then ' Before reading, show the symbologies the engine is going to try to read Console.WriteLine("Trying to read the following symbologies:") Dim symbologies As BarcodeSymbology() = e.GetSymbologies() For i As Integer = 0 To symbologies.Length - 1 Console.Write(symbologies(i)) If i <> (symbologies.Length - 1) Then Console.Write(", ") Else Console.WriteLine() End If Next ElseIf e.Operation = BarcodeReadSymbologyOperation.PostRead Then If IsNothing(e.Error) Then ' No errors Dim barcode As BarcodeData = e.Data If Not IsNothing(barcode) Then ' Found a barcode, show it Console.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value) Else Console.WriteLine(" No barcodes found") End If Else ' Show the error Console.WriteLine("Error: {0}", e.Error.Message) ' Tell the reader top stop reading barcodes e.Status = BarcodeReadSymbologyStatus.Abort End If End If End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Barcode; using Leadtools.ImageProcessing; public void BarcodeReader_ReadSymbologyExample() { string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif"); // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode reader instance BarcodeReader reader = engine.Reader; // Load the image using(RasterCodecs codecs = new RasterCodecs()) { using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) { // Subscribe to the ReadSymbology event reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); // Read all barcodes in the image reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null); reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); } } } private void reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e) { if(e.Operation == BarcodeReadSymbologyOperation.PreRead) { // Before reading, show the symbologies the engine is going to try to read Console.WriteLine("Trying to read the following symbologies:"); BarcodeSymbology[] symbologies = e.GetSymbologies(); for(int i = 0; i < symbologies.Length; i++) { Console.Write(symbologies[i]); if(i != (symbologies.Length - 1)) { Console.Write(", "); } else { Console.WriteLine(); } } } else if(e.Operation == BarcodeReadSymbologyOperation.PostRead) { if(e.Error == null) { // No errors BarcodeData barcode = e.Data; if(barcode != null) { // Found a barcode, show it Console.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value); } else { Console.WriteLine(" No barcodes found"); } } else { // Show the error Console.WriteLine("Error: {0}", e.Error.Message); // Tell the reader top stop reading barcodes e.Status = BarcodeReadSymbologyStatus.Abort; } } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.Barcode; using Leadtools.ImageProcessing; public async Task BarcodeReader_ReadSymbologyExample() { string imageFileName = @"Assets\Barcode1.tif"; // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode reader instance BarcodeReader reader = engine.Reader; // Load the image using(RasterCodecs codecs = new RasterCodecs()) { StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName); using(RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile))) { // Subscribe to the ReadSymbology event reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); // Read all barcodes in the image reader.ReadBarcodes(image, LeadRectHelper.Empty, 0, null); reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); } } } private void reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e) { if(e.Operation == BarcodeReadSymbologyOperation.PreRead) { // Before reading, show the symbologies the engine is going to try to read Debug.WriteLine("Trying to read the following symbologies:"); BarcodeSymbology[] symbologies = e.GetSymbologies(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < symbologies.Length; i++) { sb.Append(symbologies[i].ToString()); if(i != (symbologies.Length - 1)) { sb.Append(", "); } else { sb.AppendLine(); } } Debug.WriteLine(sb.ToString()); } else if(e.Operation == BarcodeReadSymbologyOperation.PostRead) { if(e.HResult != 0) { // No errors BarcodeData barcode = e.Data; if(barcode != null) { // Found a barcode, show it Debug.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value); } else { Debug.WriteLine(" No barcodes found"); } } else { // Show the error int hResult = e.HResult; string message = string.Empty; BarcodeException barcodeException = BarcodeException.FromHResult(hResult); if (barcodeException != null) { message = barcodeException.Message; } else { RasterException rasterException = RasterException.FromHResult(hResult); if (rasterException != null) message = rasterException.Message; else message = "UnKnown error:HResult" + hResult; } Debug.WriteLine("Error: {0}", message); // Tell the reader top stop reading barcodes e.Status = BarcodeReadSymbologyStatus.Abort; } } }
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Barcode; using Leadtools.ImageProcessing; using Leadtools.Examples; public void BarcodeReader_ReadSymbologyExample(RasterImage image) { // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode reader instance BarcodeReader reader = engine.Reader; // Load the image RasterCodecs codecs = new RasterCodecs(); // Subscribe to the ReadSymbology event reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); // Read all barcodes in the image reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null); reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); } private void reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e) { if(e.Operation == BarcodeReadSymbologyOperation.PreRead) { // Before reading, show the symbologies the engine is going to try to read Console.WriteLine("Trying to read the following symbologies:"); BarcodeSymbology[] symbologies = e.GetSymbologies(); for(int i = 0; i < symbologies.Length; i++) { Console.Write(symbologies[i]); if(i != (symbologies.Length - 1)) { Console.Write(", "); } else { Console.WriteLine(); } } } else if(e.Operation == BarcodeReadSymbologyOperation.PostRead) { if(e.Error == null) { // No errors BarcodeData barcode = e.Data; if(barcode != null) { // Found a barcode, show it Console.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value); } else { Console.WriteLine(" No barcodes found"); } } else { // Show the error Console.WriteLine("Error: {0}", e.Error.Message); // Tell the reader top stop reading barcodes e.Status = BarcodeReadSymbologyStatus.Abort; } } }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Public Sub BarcodeReader_ReadSymbologyExample(ByVal image As RasterImage) ' Create a Barcode engine Dim engine As BarcodeEngine = New BarcodeEngine() ' Get the Barcode reader instance Dim reader As BarcodeReader = engine.Reader ' Load the image Dim codecs As RasterCodecs = New RasterCodecs() ' Subscribe to the ReadSymbology event AddHandler reader.ReadSymbology, AddressOf reader_ReadSymbology ' Read all barcodes in the image reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing) RemoveHandler reader.ReadSymbology, AddressOf reader_ReadSymbology End Sub Private Sub reader_ReadSymbology(ByVal sender As Object, ByVal e As BarcodeReadSymbologyEventArgs) If e.Operation = BarcodeReadSymbologyOperation.PreRead Then ' Before reading, show the symbologies the engine is going to try to read Console.WriteLine("Trying to read the following symbologies:") Dim symbologies As BarcodeSymbology() = e.GetSymbologies() Dim i As Integer = 0 Do While i < symbologies.Length Console.Write(symbologies(i)) If i <> (symbologies.Length - 1) Then Console.Write(", ") Else Console.WriteLine() End If i += 1 Loop ElseIf e.Operation = BarcodeReadSymbologyOperation.PostRead Then If e.Error Is Nothing Then ' No errors Dim barcode As BarcodeData = e.Data If Not barcode Is Nothing Then ' Found a barcode, show it Console.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value) Else Console.WriteLine(" No barcodes found") End If Else ' Show the error Console.WriteLine("Error: {0}", e.Error.Message) ' Tell the reader top stop reading barcodes e.Status = BarcodeReadSymbologyStatus.Abort End If End If End Sub