透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
このチュートリアルでは、C#コンソールアプリケーションと.NET Windowsフォームアプリケーションで、IronBarcodeライブラリを使用してQRコードおよびバーコードをスキャンする方法を示します。
IronBarcodeライブラリを使用すると、複数のバーコードを同時にスキャンして読み取ることができ、不完全な画像も正常にスキャンできます。 まず、バーコードスキャナーとは何かを明確にしましょう。
バーコードは、一連の幅が異なる平行な黒い線と白いスペースで構成された四角形または長方形の画像です。 バーコードスキャナー(バーコードリーダー)は、印刷されたバーコードを読み取り、バーコードに含まれるデータをデコードして、そのデータをコンピュータに送信できる装置です。
以下の手順では、IronBarcodeライブラリを使用してバーコードスキャナーを作成する方法を紹介します。
Visual Studio を開く > Create New Project をクリック > Windows Forms Application Template を選択 > Next を押す > プロジェクトに名前を付ける > Next を押す > 対象とする .NET Framework を選択 > Create ボタンをクリック。
プロジェクトを作成した後、Visual Studioツールボックスから以下のようにフォームをデザインします:PictureBox、Label、TextBox、およびButtonコントロール。
バーコードスキャナー
バーコードライブラリをインストールするには、以下の3つの方法のいずれかを使用できます:
以下のコマンドをパッケージマネージャーコンソールに入力してください。 パッケージをダウンロードしてインストールします。
Install-Package BarCode
バーコードライブラリは、NuGetパッケージソリューションを使用してインストールすることもできます。 次の手順に従うだけです:
ツール > NuGet パッケージ マネージャー > ソリューションの NuGet パッケージを管理 をクリックします。
これは、NuGetパッケージマネージャーを開きます。 「ブラウズ」をクリックし、「Barcode」を検索して、クラスライブラリをインストールしてください。
代替手段として、IronBarCode.Dll をダウンロードしてプロジェクトに参照として追加することができます。
ダウンロードした後、次の参照をバーコードリーダープロジェクトに追加してください。
using IronBarCode;
using IronBarCode;
Imports IronBarCode
.NETでバーコードまたはQRコードを読み取ることは、.NET Barcode Readerを使用したIronBarcodeライブラリを使用すると非常に簡単です。
プロジェクト内で読み取りたい画像を参照してください。 それはPictureBox
で開かれます。 「scan code」をクリックしてください。 テキストはテキストボックスに表示されます。
以下は、画像を開くための「browse」ボタンのコードです:
// open file dialog
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)
*.jpg;*.png;*.jpeg;*.gif;*.bmp";
if (open.ShowDialog() == DialogResult.OK) {
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
// store image file path in class data member. Initialize it as string ImageFileName;
ImageFileName = open.FileName;
}
// open file dialog
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)
*.jpg;*.png;*.jpeg;*.gif;*.bmp";
if (open.ShowDialog() == DialogResult.OK) {
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
// store image file path in class data member. Initialize it as string ImageFileName;
ImageFileName = open.FileName;
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
「scan code」ボタンのコード:
BarcodeResult Result = BarcodeReader.Read(ImageFileName);
textBox1.Text = Result.Text;
BarcodeResult Result = BarcodeReader.Read(ImageFileName);
textBox1.Text = Result.Text;
Dim Result As BarcodeResult = BarcodeReader.Read(ImageFileName)
textBox1.Text = Result.Text
バーコードスキャナーは、以下のようにテキストボックスにバーコードデータを表示します:
Barcode イメージを C# でスキャンする
このセクションでは、IronBarcodeライブラリが傾いたQRコードに関する実際の状況を効果的に処理します。 斜めのQRコードはRead
メソッドで処理および読み取りが可能ですが、解決により多くの時間がかかることがあります。 IronBarcodeライブラリは、このような画像入力を処理するための追加のパラメーターとしてBarcodeReaderOptions
を使用するカスタマイズされた方法を提供します。 コードは次のようになります:
// Choose which filters are to be applied (in order);
var filtersToApply = new ImageFilterCollection() {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter()
};
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Set chosen filters in BarcodeReaderOptions:
ImageFilters = filtersToApply,
ExpectBarcodeTypes = BarcodeEncoding.QRCode
BarcodeEncoding.Code128,
};
BarcodeResult Result = BarcodeReader.Read(ImageFileName, myOptionsExample);
textBox1.Text = Result.Text;
// Choose which filters are to be applied (in order);
var filtersToApply = new ImageFilterCollection() {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter()
};
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Set chosen filters in BarcodeReaderOptions:
ImageFilters = filtersToApply,
ExpectBarcodeTypes = BarcodeEncoding.QRCode
BarcodeEncoding.Code128,
};
BarcodeResult Result = BarcodeReader.Read(ImageFileName, myOptionsExample);
textBox1.Text = Result.Text;
IRON VB CONVERTER ERROR developers@ironsoftware.com
傾いたQRコード画像を開いた後、出力は次のようになります:
傾斜したQrCode画像
バーコード画像はPDFファイルからスキャンでき、その結果は望むように適切に表示することができます。 以下のサンプルコードは、PDFファイルから複数のバーコードを読み取ることができます。
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input
imagePagedBarcodeResult [] PDFResults = BarcodeReader.ReadPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var PageResult in PDFResults) {
string Value = PageResult.Value;
int PageNum = PageResult.PageNumber;
System.Drawing.Bitmap Img = PageResult.BarcodeImage;
BarcodeEncoding BarcodeType = PageResult.BarcodeType;
byte [] Binary = PageResult.BinaryValue;
Console.WriteLine(PageResult.Value + " on page " + PageNum);
}
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input
imagePagedBarcodeResult [] PDFResults = BarcodeReader.ReadPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var PageResult in PDFResults) {
string Value = PageResult.Value;
int PageNum = PageResult.PageNumber;
System.Drawing.Bitmap Img = PageResult.BarcodeImage;
BarcodeEncoding BarcodeType = PageResult.BarcodeType;
byte [] Binary = PageResult.BinaryValue;
Console.WriteLine(PageResult.Value + " on page " + PageNum);
}
' Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input
Dim PDFResults() As imagePagedBarcodeResult = BarcodeReader.ReadPdf("MultipleBarcodes.pdf")
' Work with the results
For Each PageResult In PDFResults
Dim Value As String = PageResult.Value
Dim PageNum As Integer = PageResult.PageNumber
Dim Img As System.Drawing.Bitmap = PageResult.BarcodeImage
Dim BarcodeType As BarcodeEncoding = PageResult.BarcodeType
Dim Binary() As Byte = PageResult.BinaryValue
Console.WriteLine(PageResult.Value & " on page " & PageNum)
Next PageResult
PDFファイルに含まれるバーコードおよびQRコード:
C# - PDFからバーコードを読み取る結果
現実のユースケースでは、バーコードはしばしば画像、スキャン、サムネイル、または写真に欠陥があり、デジタルノイズを含んでいたり、傾いていたりすることがあります。 このセクションでは、サムネイルからバーコードデータを読み取る方法を示します。
IronBarcode ライブラリは C# Barcode Generator を使用しており、破損したバーコードのサムネイルを読み取ることさえ可能です。
自動バーコードサムネイルサイズ補正。 IronBarcodeを使用してC#で読み取り可能なファイル
それは、実際のバーコードとして合理的に表現するには小さすぎるバーコード画像を自動的に検出し、その後、すべてのサムネイル処理に関連するデジタルノイズをスケールアップしてクリーンアップし、それによって再び読み取り可能にします。
// Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.Read("ThumbnailOfBarcode.gif");
// Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.Read("ThumbnailOfBarcode.gif");
' Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
Dim SmallResult As BarcodeResult = BarcodeReader.Read("ThumbnailOfBarcode.gif")
IronBarcodeは、多様な.NETソフトウェアライブラリであり、C# QRコードジェネレーターであり、広範なバーコード画像形式をスキャンおよび読み取ることができます。また、これらのバーコードが完全なスクリーンキャプチャであろうとなかろうと、あるいは写真、スキャン、その他の不完全な実世界の画像であっても処理できます。 さらに、IronBarcode は、バーコード読み取り速度を向上させるために、切り取り領域やマルチスレッド、ML モデルの精度など、幅広いカスタマイズオプションを提供します。 IronBarcodeに関する詳細情報は公式ドキュメントページをご覧ください。
現在、完全なIron Suiteを購入すると、2つの価格で5つのライブラリを手に入れることができます。