C#およびVB.NETアプリケーションでのバーコードとQRコード

Curtis Chau
Curtis Chau
更新日: 2026年8月2日

C#および他のすべての.NET言語でバーコードを読み書きすることは、IronBarcodeソフトウェアライブラリを使用することで簡単です。

IronBarcodeのインストール

旅の最初のステップはIronBarcodeのインストールで、これはNuGetからダウンロードするかDLLをダウンロードすることによって行うことができます。

IronBarcode NuGetパッケージをインストールするには、Visual StudioのNuGetパッケージマネージャを使用することができます。

PM > Install-Package BarCode

.NET CLIを使用してインストールする方法もあります。

> dotnet add package IronBarCode

バーコードまたはQRコードの読み取り

IronBarcodeを使用すると、バーコードを読み取るのは1行のコードだけです。

using IronBarCode;

BarcodeResults results = BarcodeReader.Read("QuickStart.jpg");
if (results != null)
{
    foreach (BarcodeResult result in results)
    {
        Console.WriteLine(result.Text);
    }
}

この1行のコードで、入力ドキュメントのすべてのバーコードの検出とスキャンが可能になります。また、例外的なパフォーマンスで実行されます。この方法は、JPEG、PNG、BMPなどのさまざまな画像フォーマットに加えて、PDFやGIFやTIFFといった多フレームフォーマットもサポートします。 性能を向上させるために、カスタマイズ可能な設定オプションが利用可能です。

読み取り速度を向上させるには、パフォーマンス向上のためにBarcodeReaderOptionsオブジェクトをSpeed設定で作成することができます。 デフォルトはBalancedですが、特定のチェックをスキップするためのFasterオプションも利用可能です。

using IronBarCode;
using System;
using System.Linq;

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    ExpectMultipleBarcodes = false,
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
    CropArea = new System.Drawing.Rectangle(100, 200, 300, 400),
};

BarcodeResults result = BarcodeReader.Read("QuickStart.jpg", myOptionsExample);
if (result != null)
{
    Console.WriteLine(result.First().Text);
}

また、読み取りプロセスを最適化するためにScanModeをOnlyBasicScanに設定することもできます。

using IronBarCode;

BarcodeResults results = BarcodeReader.Read("MultipleBarcodes.png");

// Loop through the results
foreach (BarcodeResult result in results)
{
    string value = result.Value;
    Bitmap img = result.BarcodeImage;
    BarcodeEncoding barcodeType = result.BarcodeType;
    byte[] binary = result.BinaryValue;
    Console.WriteLine(result.Value);
}

他の設定では、スキャンするバーコード形式を指定でき、不要なスキャンを減らすことで処理を高速化することができます。

using IronBarCode;

BarcodeResults pagedResults = BarcodeReader.Read("MultipleBarcodes.pdf");

// Loop through the results
foreach (BarcodeResult result in pagedResults)
{
    int pageNumber = result.PageNumber;
    string value = result.Value;
    Bitmap img = result.BarcodeImage;
    BarcodeEncoding barcodeType = result.BarcodeType;
    byte[] binary = result.BinaryValue;
    Console.WriteLine(result.Value);
}

// or from a multi-page  TIFF scan with image correction:
BarcodeResults multiFrameResults = BarcodeReader.Read(inputImage: "Multiframe.tiff", new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Detailed,
    ExpectMultipleBarcodes = true,
    ExpectBarcodeTypes = BarcodeEncoding.Code128,
    Multithreaded = false,
    RemoveFalsePositive = false,
    ImageFilters = null
});

バーコードの書き込み

IronBarcodeを使ってバーコードを書くには、BarcodeWriterクラスを使用します。

using IronBarCode;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.SaveAsImage("myBarcode.png");

バーコードのスタイリング

IronBarcodeは、バーコードの視覚的表現を操作するためのいくつかのオプションを提供します。

using IronBarCode;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.AddAnnotationTextAboveBarcode("Product URL:");
myBarcode.AddBarcodeValueTextBelowBarcode();
myBarcode.SetMargins(100);
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple);

// All major image formats supported as well as PDF and HTML
myBarcode.SaveAsPng("myBarcode.png");

バーコードのHTMLとしてのエクスポート

IronBarcodeは、バーコードをHTMLドキュメントとして、またはHTMLコンテンツの一部としてエクスポートできます。

using IronBarCode;

QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf");

QRコードの生成

QRコードのためには、エラー訂正のようなQR固有の機能の追加設定を提供するQRCodeWriterクラスを使用します。

using IronBarCode;
using IronSoftware.Drawing;

QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo);
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf");

サポートされるバーコード形式

IronBarcodeは、読み書きの両方で多くの一般的に使用されるバーコード形式をサポートしています:

  • QR、Micro QR、長方形のMicro QR (rMQR)コード。
  • Aztec、Data Matrix、MaxiCode、PDF417などの他の二次元バーコード。
  • Databarなどのスタック型一次元バーコード。
  • UPC-A、UPC-E、EAN-8、EAN-13、Codabar、ITF、MSI、Plesseyなどの通常の一次元バーコード形式。

IronBarcodeを選ぶ理由

IronBarcodeは、.NETのためのバーコードの読み書きのための開発者にとって使いやすく、実際のユースケースでの精度、精密さ、および速度を最適化するAPIを提供します。

例えば、BarcodeWriterクラスは自動的にUPCAとUPCEバーコードの『チェックサム』を検証し、修正し、数値フォーマットの制約を処理します。 IronBarcodeは、開発者がデータに最適なバーコード形式を選択するのを手助けします。

このライブラリは堅牢で、画像の事前処理技術(自動回転や画像ノイズ除去など)を使用して、バーコード検出成功率を最大化します。

今後のステップ

IronBarcodeを最大限に活用するために、このドキュメントセクション内のチュートリアルを読むことや、GitHubで私たちを訪問することをお勧めします。

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

もっと読む

準備はできましたか?

NuGetダウンロード数 2,575,633バージョン:2026.11ちょうどリリースされました