最適な読み取り速度を実現するためのバーコード切り取り領域の定義方法

ハイリル ハシミ ビン オマル
ハイリル ハシミ ビン オマル
2023年11月7日
更新済み 2024年12月10日
共有:
This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcodeの最も重要な機能の一つは、ユーザーが作物領域を指定できる能力です。 この機能の目的は、IronSoftware.Drawing.Rectangle オブジェクトを使用して、画像内の切り取り領域で指定された特定のバーコードまたは領域のみをIronBarcodeが読み取ることができるようにすることです。 この機能を使用することで、読み取りの誤差を減らすだけでなく、読み取り性能も向上します。

IronBarcodeを始める

今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer


画像内のクロップ領域の座標とサイズを見つける

ユーザーが画像内のポイントの座標を見つけるために利用できる方法は多数あります。 その一つは、コンピュータの「ペイント」アプリケーションを使用して画像を読み込むことです。 クロップ領域の最初の座標を取得するには、Rectangleの左上の角となる希望の最初の場所にカーソルを移動し、画面の左下にアプリが指定したx,y座標を取得します。 次に、Rectangleの右下の角になる第二のポイントを見つけます。 以下の画像を参照してください。

CropRegion リファレンス

その後、座標値を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)
$vbLabelText   $csharpLabel

クロップ領域の適用とバーコードの読み取り

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
$vbLabelText   $csharpLabel

上記のコードスニペットでは、BarcodeReaderOptions オブジェクト内でインスタンス化された RectangleCropArea プロパティとして使用しました。 次に、このBarcodeReaderOptionsオブジェクトをBarcodeReader.Read()メソッドのパラメータとして使用し、画像内でCropAreaを適用し、内部のバーコードを読み取ります。

ハイリル ハシミ ビン オマル
ハイリル ハシミ ビン オマル
ソフトウェアエンジニア
すべての優れたエンジニアと同じように、Hairilは熱心な学習者です。C#、Python、およびJavaの知識を洗練させ、その知識を活かしてIron Softwareのチームメンバーに価値を提供しています。Hairilはマレーシアのマラ工科大学(Universiti Teknologi MARA)で化学およびプロセス工学の学士号を取得し、Iron Softwareチームに加わりました。