最適な読み取り速度を実現するためのバーコード切り取り領域の定義方法
IronBarcodeの最も重要な機能の一つは、ユーザーがCrop Regionsを指定する能力です。 この機能の目的は、IronSoftware.Drawing.Rectangle
オブジェクトを使用して画像のトリミング領域で指定された特定のバーコードまたはエリアのみをIronBarcodeが読み取るようにすることです。 この機能を使用することで、読み取りの誤差を減らすだけでなく、読み取り性能も向上します。
IronBarcodeを始める
今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。
最適な読み取り速度を実現するためのバーコード切り取り領域の定義方法
- バーコードを読み取るためのC#ライブラリをダウンロード
- 画像内のクロップ領域の座標とサイズを見つける
- 座標からクロップ領域を作成する
- 以下を使用
読み取り
バーコードを検出して読み取る方法 - メソッドにクロップ領域オブジェクトを渡します。
画像内のクロップ領域の座標とサイズを見つける
ユーザーが画像内のポイントの座標を見つけるために利用できる方法は多数あります。 その一つは、コンピュータの「ペイント」アプリケーションを使用して画像を読み込むことです。 クロップ領域の最初の座標を取得するには、カーソルを移動して希望する最初の位置、つまり Rectangle
の左上隅に移動し、画面の左下に表示されるアプリから与えられた x,y 座標を取得します。 次に、Rectangle
の右下隅に位置する第2ポイントを見つけてください。 以下の画像を参照してください。
クロップ領域参照の設定
その後、座標値は 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に読み取ってもらいたい場合、オブジェクトを適用できます。 バーコードリーダーオプション
他の設定の他にもプロパティの1つとして、パラメーターとして使用することができます。 BarcodeReader.Read()
method. 以下のコードスニペットは
: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
上記のコードスニペットでは、インスタンス化された 長方形
イン バーコードリーダーオプション
オブジェクトをのように クロップエリア (CropArea)
プロパティ。 次にこれを使用します。 バーコードリーダーオプション
次の文のパラメータとしてのオブジェクト BarcodeReader.Read()
method to apply the CropArea in the image and read the barcodes inside.