IronBarcodeとZXing.NETの比較
バーコードスキャナーは、必ずしもわれわれのアプリケーションに適しているとは限りません。 あなたはすでにバーコードのデジタル画像をお持ちで、その内容が英文で何を表しているのか知りたいと思っているかもしれません。 さらに、このスキャナーは1Dバーコードのみを読み取ることができ、Windows RTクラスライブラリでのみ使用可能です。 2Dバーコード(QRコードとしても知られています)は今では一般的で、より多くの情報を保持することができます。
C#ベースのアプリケーションは、簡単なAPIコールと少しのコーディングステップでバーコードを読み取るために作成することができます。 .NET対応のアプリケーションは、サードパーティツールやAPIに頼らずにWindows、macOS、Linux上で動作します。
この記事では、プログラムでバーコードを読み取るための2つの最も強力な.NET Coreアプリライブラリを比較します。 これら2つのライブラリはIronBarcodeとZXing.NETです。 IronBarcodeがZXing.NETよりも強力で堅牢である理由を見ていきましょう。
Zxing を使用して C# でバーコードを生成する方法
- バーコードを生成するためのC#ライブラリをインストールする
- バーコードをカスタマイズするために、
BarcodeWriterPixelDataクラスから新しいオブジェクトを作成します。 Formatプロパティでバーコードの種類を設定するQrCodeEncodingOptionsクラスをインスタンス化して、高さ、太さ、余白をさらにカスタマイズします。- ステップ2のオブジェクトの
Writeメソッドを使用してC#でバーコードを生成します。
ZXing.NETとは
ZXing.NETは、バーコード(QRコード、PDF 417、EAN、UPC、Aztec、Data Matrix、Codabarなど)をデコードおよび生成するライブラリです。 ZXingは"zebra crossing"の略で、Javaベースのオープンソースライブラリであり、さまざまな1Dおよび2Dバーコード形式をサポートしています。
主要な特長は以下の通りです:
- URL、連絡先情報、カレンダーイベントなどを保存する機能があります
- Java SE アプリケーションに特化しています
- インテントを介してバーコードスキャナーの統合を提供します
- 簡単なGoogle Glassアプリです
IronBarcodeとは
IronBarcodeは、プログラマーがバーコードを読み取り生成できるC#ライブラリです。 主要なバーコードライブラリとして、IronBarcodeは、装飾(カラーとブランド)QRコードを含むさまざまな1次元および2次元バーコードをサポートしています。 .NET StandardとCoreバージョン2以上をサポートしており、Azure、Linux、macOS、Windows、およびWebでクロスプラットフォームで使用できます。 IronBarcodeは、C#、VB.NET、F#開発者が標準化されたプログラミング言語を利用できる.NETシステムのクラスライブラリまたはコンポーネントとして知られています。 お客様はスキャナータグを参照して新しい標準ラベルを作成することができます。 2Dバーコードやその他の3D標準化バーコードに優れた動作をします。
IronBarcodeは現在、2Dバーコードをサポートしています。 これらのコードのカラーリング、スタイリング、ピクセル化を最適化する機能と、印刷または広告資料で使用するためのロゴを追加する機能を提供します。 このライブラリは、他のバーコードソフトウェアでは読み取ることができない歪んだバーコードや変形したバーコードを読むこともできます。
IronBarcodeとZXing.NETのインストール
ZXing.NETのインストール
ZXing.NETライブラリを使用するには、ASP.NET Core アプリケーションに以下の2つのパッケージを NuGet パッケージマネージャーコンソールを使用してインストールします:
1. ZXing.Net
Install-Package ZXing.Net
2. ZXing.Net.Bindings.CoreCompat.System.Drawing
Install-Package ZXing.Net.Bindings.CoreCompat.System.Drawing -Version 0.16.5-beta
あるいは、NuGet パッケージマネージャを使用してプロジェクトに ZXing.NET をインストールします。 これを行うには、ツール > NuGet パッケージマネージャ > ソリューションのNuGet パッケージを管理...を開き、"ZXing.NET"を"参照"タブで検索します。

ASP.NET Webアプリケーション
IronBarcodeのインストール
IronBarcodeは、NuGet パッケージマネージャまたは製品ウェブサイトから DLL を直接ダウンロードすることでインストールできます。 IronBarcode の名前空間に IronBarcode クラスがすべて含まれています。
IronBarcode は、Visual Studio の NuGet パッケージマネージャを使用してインストールできます:パッケージ名は"Barcode"です。
Install-Package BarCode
2Dバーコードの作成
ZXing.NETを使用する
まず、プロジェクトファイルのルートフォルダー内に"qrr"という新しいフォルダーを作成します。
次に、QRファイルを作成し、"qrr"フォルダー内の画像システムファイルに保存します。
コントローラー内に GenerateFile() メソッドを追加し、以下のソースコードのように記述します。
public ActionResult GenerateFile()
{
return View();
}
[HttpPost]
public ActionResult GenerateFile(string qrText)
{
Byte [] byteArray;
var width = 250; // width of the QR Code
var height = 250; // height of the QR Code
var margin = 0;
// BarcodeWriterPixelData acts as a QR code generator
var qrCodeWriter = new ZXing.BarcodeWriterPixelData
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = height,
Width = width,
Margin = margin
}
};
var pixelData = qrCodeWriter.Write(qrText);
// creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
using (var ms = new MemoryStream())
{
var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
try
{
// we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
// Save to folder
string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
// Save to stream as PNG
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byteArray = ms.ToArray();
}
}
return View(byteArray);
}public ActionResult GenerateFile()
{
return View();
}
[HttpPost]
public ActionResult GenerateFile(string qrText)
{
Byte [] byteArray;
var width = 250; // width of the QR Code
var height = 250; // height of the QR Code
var margin = 0;
// BarcodeWriterPixelData acts as a QR code generator
var qrCodeWriter = new ZXing.BarcodeWriterPixelData
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = height,
Width = width,
Margin = margin
}
};
var pixelData = qrCodeWriter.Write(qrText);
// creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
using (var ms = new MemoryStream())
{
var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
try
{
// we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
// Save to folder
string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
// Save to stream as PNG
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byteArray = ms.ToArray();
}
}
return View(byteArray);
}残された唯一の変更点は、"qrr"フォルダー内にQRコードファイルを保存することです。 これは、以下の2行のコードを使用して行われます。
string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);次に、GenerateFile ビューを作成し、その中に以下のコードを含めます。 GenerateFile ビューは、インデックスビューと同じです。
@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
<table>
<tbody>
<tr>
<td>
<label>Enter text for creating QR Code</label>
</td>
<td>
<input type="text" name="qrText" />
</td>
</tr>
<tr>
<td colspan="2">
<button>Submit</button>
</td>
</tr>
</tbody>
</table>
}
@{
if (Model != null)
{
<h3>QR Code Successfully Generated</h3>
<img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
}
}@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
<table>
<tbody>
<tr>
<td>
<label>Enter text for creating QR Code</label>
</td>
<td>
<input type="text" name="qrText" />
</td>
</tr>
<tr>
<td colspan="2">
<button>Submit</button>
</td>
</tr>
</tbody>
</table>
}
@{
if (Model != null)
{
<h3>QR Code Successfully Generated</h3>
<img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
}
}テキストボックスに任意の値を入力し、"送信"ボタンを押します。 QRコードが生成され、"qrr"フォルダーに.PNGファイルとして保存されます。

QR Code Generator

表示されるQRコードファイル
サポートされているバーコードフォーマット
IronBarcodeは、以下のように一般的に使用される幅広いバーコード形式をサポートしています:
- ロゴと色のあるQRコード(装飾されたおよびブランドのコードを含む)
- Aztec、Data Matrix、CODE 93、CODE 128、RSS Expanded Databar、UPS MaxiCode、およびUSPS、IMB(OneCode)バーコードを含む多様なフォーマットのバーコード
- RSS-14およびPDF-417スタック線形バーコード
- UPCA、UPCE、EAN-8、EAN-13、Codabar、ITF、MSI、Plesseyといった伝統的な数値バーコードフォーマット
バーコードの作成と保存
using IronBarCode;
// Create a barcode and save it in various formats
var MyBarCode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
// Convert barcode to different image formats and obtain binary data
System.Drawing.Image MyBarCodeImage = MyBarCode.Image;
System.Drawing.Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte[] PngBytes = MyBarCode.ToPngBinaryData();
// Save barcode in PDF stream
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
// The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}
// Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);using IronBarCode;
// Create a barcode and save it in various formats
var MyBarCode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
// Convert barcode to different image formats and obtain binary data
System.Drawing.Image MyBarCodeImage = MyBarCode.Image;
System.Drawing.Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte[] PngBytes = MyBarCode.ToPngBinaryData();
// Save barcode in PDF stream
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
// The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}
// Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);一方、ZXingは、Javaベースのオープンソースの1D/2Dバーコード画像処理ライブラリです。 UPC-A、UPC-E、EAN-8、Code 93、Code 128、QRコード、Data Matrix、Aztec、PDF 417などのバーコード形式がサポートされています。

サポートされているバーコード形式
IronBarcodeを使用したQRコードファイル作成
IronBarcodeでQRコードを作成するには、QRCodeWriterクラスを使用することができ、BarcodeWriterクラスの代わりに使用します。 このクラスはQRコードを作成するための新規および興味深い機能を導入しています。 QRエラー補正レベルを設定することで、QRコードのサイズと読みやすさのバランスを取ることができます。
using IronBarCode;
// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");using IronBarCode;
// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");エラー補正により、実社会でQRコードを読みやすくすることができます。 エラー補正レベルが高いほど、QRコードはより大きく、ピクセルや複雑さが増加します。 以下の画像では、QRコードファイルが表示されています。

QRコード画像
まず、IronBarcode.BarcodeWriterEncoding列挙型からバーコードの値とバーコード形式を指定します。 その後、画像として、System.Drawing.Imageとして、またはビットマップコードオブジェクトとして保存できます。
using IronBarCode;
using System.Diagnostics;
// Generate a simple BarCode image and save as PNG using the following namespaces
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");
// This line opens the image in your default image viewer
Process.Start("MyBarCode.png");using IronBarCode;
using System.Diagnostics;
// Generate a simple BarCode image and save as PNG using the following namespaces
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");
// This line opens the image in your default image viewer
Process.Start("MyBarCode.png");
C# でバーコード画像を作成する例
IronBarcodeは、QRコードのスタイリングもサポートしており、画像の正確な中心にロゴグラフィックを配置してスナップすることができます。 特定のブランドやグラフィックアイデンティティに合わせて色を変更することもできます。
テスト用に、以下のコードサンプルでロゴを作成し、QRCodeWriter.CreateQRCodeWithLogoメソッドを使用するのがどれほど簡単かを確認してください。
using IronBarCode;
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);using IronBarCode;
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
ロゴ画像付きQRコードを作成する
最後に、生成されたQRコードをPDFファイルとして保存します。便利のため、最終コード行はQRコードをHTMLファイルとして保存します。
using IronBarCode;
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");
// Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");using IronBarCode;
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");
// Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");以下では、わずか1行のコードでバーコードを作成、スタイリング、エクスポートする方法を示しています。
IronBarcodeには、System.Linqに似た流れるようなAPIが含まれています。 メソッドコールを連鎖させることで、バーコードを作成し、そのマージンを設定し、それをビットマップにエクスポートします。 これは非常に便利で、コードを読みやすくします。
using IronBarCode;
using System.Drawing;
// Fluent API for Barcode image generation
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417)
.ResizeTo(300, 200)
.SetMargins(100)
.ToBitmap();using IronBarCode;
using System.Drawing;
// Fluent API for Barcode image generation
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417)
.ResizeTo(300, 200)
.SetMargins(100)
.ToBitmap();その結果、次に示すようなPDF417バーコードのSystem.Drawing.Imageが作成されます:

C# でシンプルかつスムーズに PDF417 バーコードを生成
QRコードファイルを読む
IronBarcodeを使用してQRコードを読む
.NETバーコードリーダーと連携したIronBarcodeクラスライブラリを使用すると、バーコードまたはQRコードの読み取りは簡単です。 最初の例では、たった1行のコードでバーコードを読む方法を示しています。

C#でスキャンするCode128バーコード画像
バーコードのバリュー、画像、エンコーディングタイプ、バイナリデータ(ある場合)を取得した後、それをコンソールに出力します。
using IronBarCode;
using System;
// Read a barcode or QR code from an image
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result != null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
Console.WriteLine("GetStarted was a success. Read Value: " + Result.Text);
}using IronBarCode;
using System;
// Read a barcode or QR code from an image
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result != null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
Console.WriteLine("GetStarted was a success. Read Value: " + Result.Text);
}PDF内のバーコードを読む
スキャンしたPDF文書を読み取り、数行のコードで1次元のバーコードをすべて見つける方法について見ていきましょう。
お分かりのように、これは単一の文書から単一のバーコードを読むことに非常に似ていますが、バーコードが発見されたページ番号がわかる点が異なります。
using IronBarCode;
using System;
using System.Drawing;
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also be used as the input image
PagedBarcodeResult[] PDFResults = BarcodeReader.ReadBarcodesFromPdf("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);
}using IronBarCode;
using System;
using System.Drawing;
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also be used as the input image
PagedBarcodeResult[] PDFResults = BarcodeReader.ReadBarcodesFromPdf("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);
}PDF内の全てのビットマップバーコードを含む結果データを得ることができます。

PDF 結果内に保存されたバーコードの読み取り
GIFおよびTIFFからバーコードを読む
using IronBarCode;
using System;
// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
// Process each page result
}using IronBarCode;
using System;
// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
// Process each page result
}
マルチフレームTIFF画像からのバーコードの読み取り
次の例では、スキャンされたPDFからQRコードおよびPDF-417バーコードを読み取る方法を示します。 ドキュメントを可視的に磨くことなく重要なパフォーマンスペナルティを引き起こさない適切なバーコード回転補正レベルおよびバーコード画像補正レベルを設定しました。
using IronBarCode;
using System;
// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);
// Work with the results
foreach (var PageResult in ScanResults)
{
string Value = PageResult.Value;
//...
}using IronBarCode;
using System;
// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);
// Work with the results
foreach (var PageResult in ScanResults)
{
string Value = PageResult.Value;
//...
}
スキャンしたPDF文書からバーコードを読み取る
ビットマップ画像からの破損したQRコードを読む
以下の例は、このC#バーコードライブラリが破損したバーコードのサムネイルを読み取ることさえできることを示しています。
バーコードサムネイルサイズの補正は自動的に行われます。 C#のIronBarcodeはファイルを読み取り可能にします。
リーダーメソッドは、正当なバーコードとしては小さすぎるバーコード画像を自動的に検出し、サイズをアップスケールします。 サムネイルで作業する際のデジタルノイズをすべて除去し、再び読み取り可能にします。
using IronBarCode;
// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);using IronBarCode;
// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
バーコードサムネイルサイズの自動補正
不完全な画像からのバーコードの読み取り
実社会のシナリオでは、不完全な画像からバーコードを読みたい場合があります。 これらは傾いた画像やデジタルノイズを含む写真である場合があります。ほとんどのオープンソース.NETバーコード生成および読み取りライブラリではこれが不可能です。 一方、IronBarcodeを使うと、不完全な画像からのバーコード読み取りが簡単です。
今度はReadASingleBarcodeメソッドを見ていきましょう。 RotationCorrectionパラメーターにより、IronBarcodeは不完全なデジタルサンプルからデスクューしてバーコードを読み取ろうとします。
using IronBarCode;
using System;
using System.Drawing;
// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding e.g. BarcodeEncoding.Code128, Setting a specific Barcode format improves speed and reduces the risk of false positive results
// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);using IronBarCode;
using System;
using System.Drawing;
// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding e.g. BarcodeEncoding.Code128, Setting a specific Barcode format improves speed and reduces the risk of false positive results
// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
携帯電話のカメラからバーコードを読み取る
IronBarcodeはまた、同時に複数のバーコードを読み取ることも可能です。ドキュメントのリストを作成し、バーコードリーダーを使用して複数のドキュメントを読み取ることで、IronBarcodeから良い結果を得ることができます。 バーコードスキャンプロセスにおけるReadBarcodesMultithreadedメソッドは、複数のスレッドおよび潜在的にはCPUの全コアを使用し、バーコードを一つずつ読むよりも指数関数的に速くなる可能性があります。
using IronBarCode;
// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);
// Work with the results
foreach (var Result in BatchResults)
{
string Value = Result.Value;
//...
}using IronBarCode;
// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);
// Work with the results
foreach (var Result in BatchResults)
{
string Value = Result.Value;
//...
}ZXing.NETでのQRコードの読み取りとデコード
QRコードファイルを読み取るために、コントローラにViewFileアクションメソッドを追加します。以下に示します。
public ActionResult ViewFile()
{
List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> data;
string[] files = Directory.GetFiles(Server.MapPath("~/qrr"));
foreach (string file in files)
{
// Create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));
// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// Do something with the result
data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
fileData.Add(data);
}
return View(fileData);
}public ActionResult ViewFile()
{
List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> data;
string[] files = Directory.GetFiles(Server.MapPath("~/qrr"));
foreach (string file in files)
{
// Create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));
// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// Do something with the result
data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
fileData.Add(data);
}
return View(fileData);
}
QRコードの読み取りとデコード

デコードされたQRコード
ビットマップ内でのバーコードデコード
using ZXing;
using System.Drawing;
// Create a barcode reader instance
BarcodeReader reader = new BarcodeReader();
// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png");
// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// Do something with the result
if (result != null)
{
txtDecoderType.Text = result.BarcodeFormat.ToString();
txtDecoderContent.Text = result.Text;
}using ZXing;
using System.Drawing;
// Create a barcode reader instance
BarcodeReader reader = new BarcodeReader();
// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png");
// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// Do something with the result
if (result != null)
{
txtDecoderType.Text = result.BarcodeFormat.ToString();
txtDecoderContent.Text = result.Text;
}ZXing Decoder Online
ZXing Decoder Onlineは、デコードをサポートするオンラインのバーコードおよびQRコードスキャナーです。 QRコード画像のPNGまたはその他の形式をアップロードすると、デコードを開始します。 同様に、任意のデータのQRコードを生成できます。 ほとんどの時間、その情報はURLまたはQRコードにエンコードしたいテキストです。
ZXing Decoder のウェブサイトに移動します。

ZXingデコーダーウェブサイト

ZXing デコード結果
価格とライセンス
ZXing.NETライブラリは、無料で商用利用も可能なApache License 2.0の下で許諾されている、バーコード読み取りアプリケーションを構築するためのオープンソースライブラリです。
IronBarcodeの開発者ライセンスは無料で提供されています。 IronBarcodeは独自の価格体系を持っており:Liteバンドルは$liteLicenseから始まり、追加費用がありません。 SaaSやOEMアイテムも再配布可能です。 各ライセンスには、永続ライセンス、開発/ステージング/本番の有効性、30日間の返金保証、1年間のソフトウェアサポートとアップグレード(1回限りの購入)が含まれています。 IronBarcodeの完全な価格とライセンス情報を表示するには、このページを参照してください。
IronBarcodeを選ぶ理由
IronBarcodeは、.NETでバーコードを読み書きするための簡単に使えるAPIを含んでおり、実際の使用例において精度と低エラー率を最適化します。
たとえば、BarcodeWriterクラスは、UPCAおよびUPCEバーコードの"チェックサム"を検証および修正します。 また、特定の数値形式に入力するために短すぎる数字を"ゼロパディング"します。 指定されたデータ形式と互換性のないデータがある場合、IronBarcodeは開発者に使用可能なより適切なバーコード形式を通知します。
IronBarcodeは、バーコードをスキャンしたりフォトグラフィック画像から読み取る際に優れています。言い換えれば、画像が完全にグラフィックでなく、機械生成されたスクリーンショットでないときに、バーコードを読む際に優れています。
IronBarcodeはZXing.NETとどう違うのか?
IronBarcodeは、ZXing.NET(Zebra Crossing)コアから構築され、処理能力が改善されています。 使いやすいAPIと低エラー率がZXing.NETコアライブラリに比べて特徴です。 それだけでなく、IronBarcodeは通常のZXing.NETライブラリがサポートするよりも広範なバーコードフォーマットをサポートしています。
IronBarcodeはZXing.NETの改善されたバージョンであり、ユーザーに商業利用のためのプラットフォームと、多くのプラットフォームで同じパッケージを使用する可能性を提供します。 また、常に必要な場所で支援してくれる完全な技術サポートも備えています。
IronBarcodeは、画像内にエンコードされたバーコードの種類を検出できる自動回転、透視補正、デジタルノイズ補正も備えています。
結論
結論として、IronBarcodeは、スクリーンショット、写真、スキャン、またはその他の不完全な実社会の画像であっても、幅広いバーコード形式を読み取るための汎用.NETソフトウェアライブラリであり、C# QRコードジェネレーターです。
IronBarcodeは、バーコードを作成および識別するための最も効果的なライブラリの1つです。 バーコードを作成および識別する際にも最も迅速なライブラリの1つです。 このライブラリは異なるオペレーティングシステムと互換性があります。 設計が簡単で、さまざまなバーコード形式をサポートしています。 加えて、さまざまな記号、形式、キャラクターがサポートされています。
ZXing.NETバーコードは、さまざまな画像形式でバーコードを生成および認識する強力なライブラリです。 さまざまな形式で画像の読み取りと作成が可能です。 ZXing.NETはまた、バーコードの外観を変更することも可能で、その高さ、幅、バーコードテキストなどを変更できます。
ZXing.NETと比較して、IronBarcodeパッケージは信頼できるライセンスとサポートを提供します。 IronBarcodeの価格は$liteLicenseです。 ZXingがフリーかつオープンソースであるのに対し、IronBarcodeは包括的な商業サポートとプロフェッショナルメンテナンスを提供します。 ZXing.NETよりも柔軟性があるだけでなく、Iron Barcodeソリューションはさらに機能も備えています。 したがって、IronBarcodeがZXing.NETに対して強力なアドバンテージを持っていることは明らかです。
バーコードの認識および生成の処理時間を比較すると、IronBarcodeはZXing.NETを凌駕します。 IronBarcodeには、異なる画像形式およびPDFドキュメントからバーコードを読み取ることを可能にする多くのプロパティがあります。 さらに、他のライブラリでは利用できないバーコードやQRコード内に画像を含めることもできます。
IronBarcodeは開発初期段階で無料です。 無料トライアルを取得して、プロダクションレベルまたは商業利用に利用できます。 開発者の要件に応じて、IronBarcodeには3つの価格帯が用意されています。 あなたの需要を最も満たすソリューションを選ぶことができます。 現在、Iron Softwareの製品5つを2つのIron Software商品価格で入手できます。 詳細情報を得るには、このウェブサイトを訪れてください。
よくある質問
C#でQRコードを生成する方法は?
C#でQRコードを生成するには、`BarcodeWriter`クラスを使用してIronBarcodeを利用します。QRコードの内容を定義し、色やサイズのようなオプションをカスタマイズし、`Write`メソッドを呼び出してQRコードを生成します。
IronBarcodeがZXing.NETより堅牢な理由は何ですか?
IronBarcodeは、より広範なバーコード形式のサポートや回転および視点の補正などの高度な画像処理機能、そしてロゴと色を使用してデコレーションされたQRコードを作成する機能など、強化された機能を提供します。また、クロスプラットフォーム互換性を備え、商業サポートを提供します。
不完全な画像からバーコードをIronBarcodeで読み取ることができますか?
はい、IronBarcodeは、回転補正、視点補正、デジタルノイズ削減などの機能を使用して不完全な画像からバーコードを読み取ることができ、スキャンしたり写真に撮った画像に対して効果を発揮します。
C#でバーコードを読み取る手順は何ですか?
C#でバーコードを読み取るには、IronBarcodeの`BarcodeReader`クラスを使用します。`BarcodeReader.QuicklyReadOneBarcode`メソッドを使用してバーコードを含む画像を読み込み、認識された場合はバーコードの内容をデコードして返します。
IronBarcodeはどのようにクロスプラットフォーム互換性を扱いますか?
IronBarcodeは、Windows、macOS、Linux、およびAzureに対してクロスプラットフォーム互換性をサポートしており、サードパーティの依存関係なしに多様な.NETアプリケーションにバーコードの生成および読み取り機能を統合することができます。
IronBarcodeでQRコードをカスタマイズするためのオプションは何ですか?
IronBarcodeは、色の調整、ブランディングのためのロゴの追加、およびサイズと可読性のバランスを取るためのエラー訂正レベルの設定など、QRコードのカスタマイズを可能にし、さまざまな美的および機能的な要件に柔軟性を提供します。
IronBarcodeを商用アプリケーションで使用する際のライセンス料はありますか?
IronBarcodeは、商用アプリケーションに適した永続ライセンスを含むさまざまなライセンスオプションを提供します。これは無料であるが商用使用に制限のあるZXing.NETとは対照的です。
バーコードライブラリを使用する際の一般的なトラブルシューティングのシナリオは何ですか?
一般的な問題には、画像の質の悪さによる不正確なバーコード認識、サポートされていないバーコード形式、または構成エラーなどがあります。IronBarcodeの高度な画像処理は、一部の認識問題を軽減するのに役立ちます。
バーコード処理においてIronBarcodeを選ぶ理由は?
IronBarcodeは、より堅牢なAPI、より良いエラー処理、幅広いバーコード形式サポート、および視覚的にカスタマイズされたQRコードを生成する機能を提供し、商業用ライセンスおよびプロフェッショナルサポートの追加のメリットがあります。
IronBarcodeを.NETプロジェクトにインストールする方法は?
Visual StudioのNuGetパッケージマネージャーを使用して.NETプロジェクトにIronBarcodeをインストールできます。'IronBarcode'を検索してプロジェクトに追加し、容易な統合と更新を確実にします。








