Leadtools.Barcode名前空間 :BarcodeReadOptionsクラス |
[TypeConverterAttribute()] [SerializableAttribute()] public abstract class BarcodeReadOptions : BarcodeOptions, System.ICloneable
'Declaration
<TypeConverterAttribute()> <SerializableAttribute()> Public MustInherit Class BarcodeReadOptions Inherits BarcodeOptions Implements System.ICloneable
'Usage
Dim instance As BarcodeReadOptions
public sealed class BarcodeReadOptions : System.ICloneable
@interface LTBarcodeReadOptions : LTBarcodeOptions
public abstract class BarcodeReadOptions extends BarcodeOptions
function Leadtools.Barcode.BarcodeReadOptions()
[TypeConverterAttribute()] [SerializableAttribute()] public ref class BarcodeReadOptions abstract : public BarcodeOptions, System.ICloneable
注意:LEADTOOLS for Windows Runtimeでは、このクラスはIBarcodeReadOptionsインターフェースに相当します。
BarcodeReaderクラスには、単一または複数のバーコードを1つの画像から読み取るための複数のメソッドが含まれます(「BarcodeReader.ReadBarcodeとBarcodeReader.ReadBarcodesメソッド」参照)。BarcodeReaderは、見つかったバーコードごとに、そのバーコードデータが格納されたBarcodeDataのインスタンスを返します。
BarcodeReadOptionsクラスおよびその派生タイプは、LEADTOOLSを使ってバーコードを読み取る際に使用するオプションを制御するために使用します。オプションの設定方法には次の2通りがあります。
BarcodeReaderクラスには、各バーコード体系(または共通バーコード体系のグループ)のデフォルトオプションが含まれます。これらのオプションを取得するには、対象のバーコード体系を渡してBarcodeReader.GetDefaultOptionsメソッドを呼び出します。その後で、返されたBarcodeReadOptionsのメンバを変更できます(または、適切な派生クラスにキャストしてからそのメンバを変更します)。
また、いずれかの派生BarcodeReadOptionsクラスのインスタンスを作成し、単一のオプションまたはオプションの配列を入力パラメーターとして受け取るBarcodeReader.ReadBarcodeメソッドおよびBarcodeReader.ReadBarcodesメソッドでそのインスタンスを直接使用することもできます。
BarcodeReadOptionsのメンバとその機能を以下に示します。
メンバ | 説明 |
---|---|
BarcodeReadOptions.ForeColor |
カラー画像からバーコードを読むとき、使うバーコード前景色(バーまたはシンボルのカラー)を制御します。 |
BarcodeReadOptions.BackColor |
カラー画像からバーコードを読むとき、使うバーコード背景色(スペースのカラー)を制御します。 |
BarcodeReadOptions.LoadとBarcodeReadOptions.Save |
保存するか、XMLファイルまたはストリームへ/からオプションをロードするのに用いられることができます。 |
BarcodeReadOptions.GetSupportedSymbologiesとBarcodeReadOptions.IsSupportedSymbology |
すべてのBarcodeSymbologyのものをこのBarcodeReadOptions型によってサポートさせるか、特定のシンボルがいつサポートされるかについて調べるのに用いられることができます。 |
BarcodeReadOptionsは抽象クラスであり、直接作成することはできません。その代わりに、いずれかの派生クラスを作成します。
読まれたオプションクラス | 説明 |
---|---|
OneDBarcodeReadOptions |
規格基準1D一次元バーコードオプション。以下のバーコード体系のどれでも読むとき、使われます:EAN13、EAN8、UPCA、UPCE、Code3Of9、Code128、CodeInterleaved2Of5、Codabar、UCCEAN128、Code93、EANEXT5、EANEXT2、MSI、Code11、CodeStandard2Of5、GS1Databar、GS1DatabarLimitedまたはGS1DatabarExpanded |
GS1DatabarStackedBarcodeReadOptions |
GS1 Databar stackedは、オプションをバーコード化します。GS1DatabarStackedまたはGS1DatabarExpandedStackedバーコード体系を読むとき、使われます |
FourStateBarcodeReadOptions |
4-State barcodeオプション。AustralianPost4State、RoyalMail4StateまたはUSPS4Stateバーコード体系を読むとき、使われます |
PostNetPlanetBarcodeReadOptions |
PSTNET/Planetバーコードオプション。PostNetまたはPlanetバーコード体系を読むとき、使われます |
PatchCodeBarcodeReadOptions |
Patch codeバーコードオプション。PatchCodeシンボルを読むとき、使われます。 |
DatamatrixBarcodeReadOptions |
Datamatrixバーコードオプション。Datamatrixシンボルを読むとき、使われます。 |
MicroPDF417BarcodeReadOptions |
Micro PDF417バーコードオプション。MicroPDF417シンボルを読むとき、使われます。 |
PDF417BarcodeReadOptions |
PDF417バーコードオプション。PDF417シンボルを読むとき、使われます。 |
QRBarcodeReadOptions |
QRバーコードオプション。QRシンボルを読むとき、使われます。 |
AztecBarcodeReadOptions |
Aztecバーコードオプション。Aztecシンボルを読むとき、使われます。 |
MaxiBarcodeReadOptions |
Maxiバーコードオプション。Maxiシンボルを読むとき、使われます。 |
MicroQRBarcodeReadOptions |
MicroQRバーコードオプション。MicroQRシンボルを読むとき、使われます。 |
PharmaCodeBarcodeReadOptions |
PharmaCodeは、オプションをバーコード化します。PharmaCodeシンボルを読むとき、使われます。 |
このサンプルは「水平と垂直」であるすべてのサポートされたバーコード体系のデフォルトのバーコード検索オプションを設定して、それから回転画像からバーコードを読みます。
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Public Sub BarcodeReadOptions_Example() 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) ' Rotate the image by 90, so default option of reading horizonal barcodes will not work Console.WriteLine("Rotating the image by 90 degrees") Dim rotate As New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White)) rotate.Run(image) ' Read all the barcodes from the image using default options Console.WriteLine("Reading barcodes using default options") Dim barcodes() As BarcodeData = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, Nothing) ' Show the number of barcodes found, should be 0 since default search direction is horizontal Console.WriteLine("Found {0} barcodes", barcodes.Length) ' Now create options to read barcodes horizontally and vertically Dim options() As BarcodeReadOptions = GetHorizontalAndVerticalReadBarcodeOptions(reader) ' Read again Console.WriteLine("Reading barcodes using new options") barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, options) ' Show the number of barcodes found, should all be read now Console.WriteLine("Found {0} barcodes", barcodes.Length) End Using End Using End Sub Private Shared Function GetHorizontalAndVerticalReadBarcodeOptions(ByVal reader As BarcodeReader) As BarcodeReadOptions() ' By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes ' Notice, we cloned the default options in reader so we will not change the original options Dim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone(), OneDBarcodeReadOptions) oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim fourStateReadOptions As FourStateBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone(), FourStateBarcodeReadOptions) fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim postNetPlanetReadOptions As PostNetPlanetBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone(), PostNetPlanetBarcodeReadOptions) postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim gs1StackedReadOptions As GS1DatabarStackedBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone(), GS1DatabarStackedBarcodeReadOptions) gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim patchCodeReadOptions As PatchCodeBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone(), PatchCodeBarcodeReadOptions) patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim pdf417ReadOptions As PDF417BarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone(), PDF417BarcodeReadOptions) pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim microPdf417ReadOptions As MicroPDF417BarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone(), MicroPDF417BarcodeReadOptions) microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical ' Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use ' will use the default options if an overriden is not passed Dim readOptions() As BarcodeReadOptions = _ { _ oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions _ } Return readOptions End Function 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 BarcodeReadOptions_Example() { 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)) { // Rotate the image by 90, so default option of reading horizontal barcodes will not work Console.WriteLine("Rotating the image by 90 degrees"); RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White)); rotate.Run(image); // Read all the barcodes from the image using default options Console.WriteLine("Reading barcodes using default options"); BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, null); // Show the number of barcodes found, should be 0 since default search direction is horizontal Console.WriteLine("Found {0} barcodes", barcodes.Length); // Now create options to read barcodes horizontally and vertically BarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader); // Read again Console.WriteLine("Reading barcodes using new options"); barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, options); // Show the number of barcodes found, should all be read now Console.WriteLine("Found {0} barcodes", barcodes.Length); } } } private static BarcodeReadOptions[] GetHorizontalAndVerticalReadBarcodeOptions(BarcodeReader reader) { // By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes // Notice, we cloned the default options in reader so we will not change the original options OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone() as OneDBarcodeReadOptions; oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; FourStateBarcodeReadOptions fourStateReadOptions = reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone() as FourStateBarcodeReadOptions; fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PostNetPlanetBarcodeReadOptions postNetPlanetReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone() as PostNetPlanetBarcodeReadOptions; postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; GS1DatabarStackedBarcodeReadOptions gs1StackedReadOptions = reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone() as GS1DatabarStackedBarcodeReadOptions; gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PatchCodeBarcodeReadOptions patchCodeReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone() as PatchCodeBarcodeReadOptions; patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PDF417BarcodeReadOptions pdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone() as PDF417BarcodeReadOptions; pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; MicroPDF417BarcodeReadOptions microPdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone() as MicroPDF417BarcodeReadOptions; microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; // Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use // will use the default options if an override is not passed BarcodeReadOptions[] readOptions = { oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions }; return readOptions; } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Barcode; using Leadtools.ImageProcessing; using Leadtools.Examples; public void BarcodeReadOptions_Example(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(); // Rotate the image by 90, so default option of reading horizonal barcodes will not work Console.WriteLine("Rotating the image by 90 degrees"); RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White)); rotate.Run(image); // Read all the barcodes from the image using default options Console.WriteLine("Reading barcodes using default options"); BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, null); // Show the number of barcodes found, should be 0 since default search direction is horizontal Console.WriteLine("Found {0} barcodes", barcodes.Length); // Now create options to read barcodes horizontally and vertically BarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader); // Read again Console.WriteLine("Reading barcodes using new options"); barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, options); // Show the number of barcodes found, should all be read now Console.WriteLine("Found {0} barcodes", barcodes.Length); } private static BarcodeReadOptions[] GetHorizontalAndVerticalReadBarcodeOptions(BarcodeReader reader) { // By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes // Notice, we cloned the default options in reader so we will not change the original options OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone() as OneDBarcodeReadOptions; oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; FourStateBarcodeReadOptions fourStateReadOptions = reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone() as FourStateBarcodeReadOptions; fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PostNetPlanetBarcodeReadOptions postNetPlanetReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone() as PostNetPlanetBarcodeReadOptions; postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; GS1DatabarStackedBarcodeReadOptions gs1StackedReadOptions = reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone() as GS1DatabarStackedBarcodeReadOptions; gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PatchCodeBarcodeReadOptions patchCodeReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone() as PatchCodeBarcodeReadOptions; patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; PDF417BarcodeReadOptions pdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone() as PDF417BarcodeReadOptions; pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; MicroPDF417BarcodeReadOptions microPdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone() as MicroPDF417BarcodeReadOptions; microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; // Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use // will use the default options if an overriden is not passed BarcodeReadOptions[] readOptions = { oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions }; return readOptions; }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Barcode Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Public Sub BarcodeReadOptions_Example(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() ' Rotate the image by 90, so default option of reading horizonal barcodes will not work Console.WriteLine("Rotating the image by 90 degrees") Dim rotate As RotateCommand = New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White)) rotate.Run(image) ' Read all the barcodes from the image using default options Console.WriteLine("Reading barcodes using default options") Dim barcodes As BarcodeData() = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, Nothing) ' Show the number of barcodes found, should be 0 since default search direction is horizontal Console.WriteLine("Found {0} barcodes", barcodes.Length) ' Now create options to read barcodes horizontally and vertically Dim options As BarcodeReadOptions() = GetHorizontalAndVerticalReadBarcodeOptions(reader) ' Read again Console.WriteLine("Reading barcodes using new options") barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, options) ' Show the number of barcodes found, should all be read now Console.WriteLine("Found {0} barcodes", barcodes.Length) End Sub Private Shared Function GetHorizontalAndVerticalReadBarcodeOptions(ByVal reader As BarcodeReader) As BarcodeReadOptions() ' By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes ' Notice, we cloned the default options in reader so we will not change the original options Dim oneDReadOptions As OneDBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone(), OneDBarcodeReadOptions) oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim fourStateReadOptions As FourStateBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone(), FourStateBarcodeReadOptions) fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim postNetPlanetReadOptions As PostNetPlanetBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone(), PostNetPlanetBarcodeReadOptions) postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim gs1StackedReadOptions As GS1DatabarStackedBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone(), GS1DatabarStackedBarcodeReadOptions) gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim patchCodeReadOptions As PatchCodeBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone(), PatchCodeBarcodeReadOptions) patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim pdf417ReadOptions As PDF417BarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone(), PDF417BarcodeReadOptions) pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim microPdf417ReadOptions As MicroPDF417BarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone(), MicroPDF417BarcodeReadOptions) microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical ' Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use ' will use the default options if an overriden is not passed Dim readOptions As BarcodeReadOptions() = { oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions } Return readOptions End Function
BarcodeReadOptionsメンバ
Leadtools.Barcode名前空間
OneDBarcodeReadOptionsクラス
GS1DatabarStackedBarcodeReadOptionsクラス
FourStateBarcodeReadOptionsクラス
PostNetPlanetBarcodeReadOptionsクラス
PatchCodeBarcodeReadOptionsクラス
DatamatrixBarcodeReadOptionsクラス
MicroPDF417BarcodeReadOptionsクラス
PDF417BarcodeReadOptionsクラス
QRBarcodeReadOptionsクラス
BarcodeReaderクラス
BarcodeSymbology列挙体
BarcodeEngineクラス
BarcodeReader.ReadBarcode
BarcodeReader.ReadBarcodes
LEADTOOLSバーコードによるプログラミング
サポートされているバーコード体系
バーコードサポートのロック解除
読み取りバーコードチュートリアル