最適な読み取り速度を実現するためのバーコード切り取り領域の定義方法
IronBarcodeの最も重要な機能の一つは、ユーザーが作物領域を指定できる能力です。 この機能の目的は、IronSoftware.Drawing.Rectangle
オブジェクトを使用して、画像内の切り取り領域で指定された特定のバーコードまたは領域のみをIronBarcodeが読み取ることができるようにすることです。 この機能を使用することで、読み取りの誤差を減らすだけでなく、読み取り性能も向上します。
IronBarcodeを始める
今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。
最適な読み取り速度を実現するためのバーコード切り取り領域の定義方法
- Download the C# library for reading barcodes
- 画像内の作物領域の座標とサイズを見つける
- 座標から切り取り領域を作成する
- バーコードを検出し読み取るには、
Read
メソッドを使用してください。 - メソッドにクロップ領域オブジェクトを渡します。
画像内のクロップ領域の座標とサイズを見つける
ユーザーが画像内のポイントの座標を見つけるために利用できる方法は多数あります。 その一つは、コンピュータの「ペイント」アプリケーションを使用して画像を読み込むことです。 クロップ領域の最初の座標を取得するには、Rectangle
の左上の角となる希望の最初の場所にカーソルを移動し、画面の左下にアプリが指定したx,y座標を取得します。 次に、Rectangle
の右下の角になる第二のポイントを見つけます。 以下の画像を参照してください。

クロップ領域参照の設定
その後、座標値をRectangle
オブジェクトのプロパティとして使用できます。 オブジェクトの幅はx2 - x1として定義でき、高さはy2 - y1として定義できます。
:path=/static-assets/barcode/content-code-examples/how-to/set-crop-region-instantiate-CropRegion.cs
using IronBarCode;
int x1 = 62;
int y1 = 29;
int x2 = 345;
int y2 = 522;
IronSoftware.Drawing.Rectangle crop1 = new IronSoftware.Drawing.Rectangle(x: x1, y: y1, width: x2-x1, height: y2-y1);
Imports IronBarCode
Private x1 As Integer = 62
Private y1 As Integer = 29
Private x2 As Integer = 345
Private y2 As Integer = 522
Private crop1 As New IronSoftware.Drawing.Rectangle(x:= x1, y:= y1, width:= x2-x1, height:= y2-y1)
クロップ領域の適用とバーコードの読み取り
IronBarcodeに読み取ってほしいCropRegionsを定義するという難しい作業を終えると、それを他の設定と共にプロパティの1つとしてBarcodeReaderOptions
に適用できます。その後、BarcodeReader.Read()
メソッドのパラメーターとして使用できます。 以下のコードスニペットは
:path=/static-assets/barcode/content-code-examples/how-to/set-crop-region-apply-CropRegion.cs
using IronBarCode;
using System;
int x1 = 62;
int y1 = 29;
int x2 = 345;
int y2 = 522;
IronSoftware.Drawing.Rectangle crop1 = new IronSoftware.Drawing.Rectangle(x: x1, y: y1, width: x2 - x1, height: y2 - y1);
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
CropArea = crop1
};
var result = BarcodeReader.Read("sample.png", options);
foreach (var item in result)
{
Console.WriteLine(item.Value);
}
Imports IronBarCode
Imports System
Private x1 As Integer = 62
Private y1 As Integer = 29
Private x2 As Integer = 345
Private y2 As Integer = 522
Private crop1 As New IronSoftware.Drawing.Rectangle(x:= x1, y:= y1, width:= x2 - x1, height:= y2 - y1)
Private options As New BarcodeReaderOptions() With {.CropArea = crop1}
Private result = BarcodeReader.Read("sample.png", options)
For Each item In result
Console.WriteLine(item.Value)
Next item
上記のコードスニペットでは、BarcodeReaderOptions
オブジェクト内でインスタンス化された Rectangle
を CropArea
プロパティとして使用しました。 次に、このBarcodeReaderOptions
オブジェクトをBarcodeReader.Read()
メソッドのパラメータとして使用し、画像内でCropAreaを適用し、内部のバーコードを読み取ります。