最新の C# スキャン ライブラリを使用して Xamarin バーコード画像を作成し、読み取る
Xamarinのバーコードソリューションは、小売、物流、在庫管理分野でAndroidおよびiOSアプリを開発・保守するモバイル開発者にとって、依然として不可欠な存在です。 マイクロソフトは2024年5月にXamarinの公式サポートを終了しましたが、数百万ものXamarinアプリが依然として稼働しており、それらのアプリは依然としてバーコードを確実に作成、スキャン、デコードする必要があります。 IronBarcodeは、わずか数行のC#コードでバーコードの生成と読み取りを処理できる.NETバーコードSDKです。 Android、iOS、Windowsプラットフォームでバーコードスキャナーおよびジェネレーターとして機能し、プロジェクト移行時には直接.NET MAUIに移行します。
IronBarcodeの無料トライアルを開始して、今すぐXamarinのバーコード読み取り機能をプロジェクトに追加しましょう。
Xamarinアプリにおけるバーコードスキャンはどのように機能するのですか?
Xamarinアプリにおけるバーコードスキャンは、カメラの映像またはデバイスに保存されたファイルからバーコード情報を取得し、そのデータをスキャンライブラリに渡してエンコードされた情報をデコードすることで機能します。 従来、多くのXamarin開発者はオープンソースのZXingライブラリ(Zebra Crossing)を使用し、新しいZXingScannerPageインスタンスを作成してナビゲーションスタックにプッシュし、OnScanResultイベントを処理してバーコードを処理していました。 このアプローチはXamarin.Formsにおける基本的なQRコードスキャン用途には有効でしたが、ZXingは何年も意味のあるバグ修正を受けておらず、開発者からは暗い場所でバーコードをスキャンする場合や、データマトリックスのような複雑なフォーマットをデコードする場合にエラーが発生するという報告が頻繁に寄せられていました。
IronBarcodeは、従来とは異なるアプローチを採用した最新のバーコードスキャナーSDKです。 IronBarcodeは、ライブカメラインターフェースを備えた専用のスキャナーページを提供するのではなく、カメラキャプチャ、ユーザーがアップロードしたファイル、スクリーンショット、PDFドキュメントなど、Xamarinアプリが提供できるあらゆるソースで動作します。 これにより、開発者がユーザーインターフェースとスキャンプロセスを完全に制御する必要があるXamarinバーコードプロジェクトにとって、柔軟性の高いスキャンライブラリとなります。 BarcodeReaderクラスは30種類以上のバーコードおよびQRコード形式をサポートしており、SDKには低照度環境下や破損したバーコードでもバーコードスキャン性能を向上させるための組み込み前処理フィルターが含まれています。
まず、XamarinソリューションにIronBarcode NuGetパッケージをインストールしてください。
Install-Package BarCode
BarCode パッケージはNuGetで入手可能で、 .NET Standard 2.0 をサポートしているため、Xamarin.Forms、Xamarin ネイティブ プロジェクト、および Microsoft の MAUI フレームワークと互換性があります。 コアSDK機能には、プラットフォーム固有のNuGetパッケージや設定手順は不要です。パッケージをインストールしたら、すぐにプロジェクトでテストしてください。
XamarinアプリでバーコードとQRコードを作成する方法は?
IronBarcodeのBarcodeWriterクラスを使えば、デバイス画面への表示、ラベル貼付、データ交換用のバーコードを簡単に生成できます。 以下の例は、1次元バーコードと2次元バーコードの両方を生成する必要があるXamarinバーコードアプリでよく使われるサンプルです。
using IronBarCode;
// Barcode generation: create a Code 128 barcode for product scanning
// Comment: BarcodeWriter handles all supported encoding formats
var barcode = BarcodeWriter.CreateBarcode(
"PROD-2025-XMR", // Value to encode in the barcode
BarcodeWriterEncoding.Code128, // Barcode format for the scanner
400, 150 // Width and height in pixels
);
// Customize the barcode: add visible text below the barcode image
// Comment: this text helps users verify the encoded value
barcode.AddBarcodeValueTextBelowBarcode();
barcode.SaveAsPng("product_barcode.png");
// Generate a QR code that users can scan with any mobile device camera
// Comment: QR codes are ideal for URLs, contact data, and Wi-Fi config
var qrCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com",
BarcodeWriterEncoding.QRCode,
300, 300
);
// Configure margins and export the QR code as image lines of pixels
qrCode.SetMargins(10);
qrCode.SaveAsPng("qr_code.png");
using IronBarCode;
// Barcode generation: create a Code 128 barcode for product scanning
// Comment: BarcodeWriter handles all supported encoding formats
var barcode = BarcodeWriter.CreateBarcode(
"PROD-2025-XMR", // Value to encode in the barcode
BarcodeWriterEncoding.Code128, // Barcode format for the scanner
400, 150 // Width and height in pixels
);
// Customize the barcode: add visible text below the barcode image
// Comment: this text helps users verify the encoded value
barcode.AddBarcodeValueTextBelowBarcode();
barcode.SaveAsPng("product_barcode.png");
// Generate a QR code that users can scan with any mobile device camera
// Comment: QR codes are ideal for URLs, contact data, and Wi-Fi config
var qrCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com",
BarcodeWriterEncoding.QRCode,
300, 300
);
// Configure margins and export the QR code as image lines of pixels
qrCode.SetMargins(10);
qrCode.SaveAsPng("qr_code.png");
Imports IronBarCode
' Barcode generation: create a Code 128 barcode for product scanning
' Comment: BarcodeWriter handles all supported encoding formats
Dim barcode = BarcodeWriter.CreateBarcode(
"PROD-2025-XMR", ' Value to encode in the barcode
BarcodeWriterEncoding.Code128, ' Barcode format for the scanner
400, 150 ' Width and height in pixels
)
' Customize the barcode: add visible text below the barcode image
' Comment: this text helps users verify the encoded value
barcode.AddBarcodeValueTextBelowBarcode()
barcode.SaveAsPng("product_barcode.png")
' Generate a QR code that users can scan with any mobile device camera
' Comment: QR codes are ideal for URLs, contact data, and Wi-Fi config
Dim qrCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com",
BarcodeWriterEncoding.QRCode,
300, 300
)
' Configure margins and export the QR code as image lines of pixels
qrCode.SetMargins(10)
qrCode.SaveAsPng("qr_code.png")
出力バーコードイメージ

上記のコードは、IronBarcodeのバーコード生成機能をわずか数行のコードで示しています。コードサンプル内の各コメントは、各ステップの目的を明確に示しています。このコードは、エンコードするデータ、BarcodeWriterEncoding列挙型から取得したバーコード形式、および出力寸法を受け取ります。 IronBarcodeのSDKは、EAN-13、Code 39、QRコード、Data Matrix、PDF417、Aztecなど、幅広いエンコード方式をサポートしています。 GeneratedBarcode のインスタンスを作成した後、ResizeTo() を使用して寸法を調整したり、SetMargins() を使用してパディングを設定したり、AddAnnotationTextAboveBarcode() を使用して表示ラベルを追加したりするなど、さまざまなカスタマイズが可能です。 生成されたバーコードは、PNG、JPEG、GIF、TIFF、またはPDF形式でエクスポートできます。しかも、AndroidやiOS向けのプラットフォーム固有のコードを記述する必要はありません。
QRコードにロゴを追加したり、バーコードの色をカスタマイズしたりといった高度な機能については、バーコード生成チュートリアルとバーコード作成例ページをご覧ください。
カメラやファイルソースからバーコードを読み取り、デコードする方法は?
IronBarcodeがXamarinバーコードソリューションとして最も価値を発揮するのは、デバイスのカメラで撮影した画像、またはユーザーのフォトライブラリから選択した画像からバーコードを読み取る場合です。 スキャン処理は、鮮明なデジタルバーコードから、扱いが難しい実世界のカメラ画像まで、あらゆるものを一貫した方法で処理します。
using IronBarCode;
// Comment: read and decode barcodes from a camera-captured file
var results = BarcodeReader.Read("scanned_photo.png");
// Iterate through each barcode scanning result
foreach (var result in results)
{
// Comment: access the decoded barcode value and format type
string value = result.Value;
string type = result.BarcodeType.ToString();
// Display the scanned barcode data to the user on screen
Console.WriteLine($"Type: {type}, Value: {value}");
}
using IronBarCode;
// Comment: read and decode barcodes from a camera-captured file
var results = BarcodeReader.Read("scanned_photo.png");
// Iterate through each barcode scanning result
foreach (var result in results)
{
// Comment: access the decoded barcode value and format type
string value = result.Value;
string type = result.BarcodeType.ToString();
// Display the scanned barcode data to the user on screen
Console.WriteLine($"Type: {type}, Value: {value}");
}
Imports IronBarCode
' Comment: read and decode barcodes from a camera-captured file
Dim results = BarcodeReader.Read("scanned_photo.png")
' Iterate through each barcode scanning result
For Each result In results
' Comment: access the decoded barcode value and format type
Dim value As String = result.Value
Dim type As String = result.BarcodeType.ToString()
' Display the scanned barcode data to the user on screen
Console.WriteLine($"Type: {type}, Value: {value}")
Next
バーコードデータの読み取り

このコードスニペットは、ファイルをリーダーに渡し、その結果をループ処理します。 BarcodeResultインスタンスはそれぞれ、バーコードの種類、デコードされたテキスト、バイナリデータ、位置座標、および信頼度スコアへのアクセスを提供し、開発者が本番環境のアプリケーションに必要なすべてを提供します。 サポートされているバーコードタイプの完全なリストについては、バーコードフォーマットのサポートページを参照してください。
バーコードスキャン性能が重要な実際の使用例(暗い場所での倉庫スキャン、移動するコンベア上の破損したバーコードの読み取り、1ページ上の複数のバーコードのデコードなど)では、BarcodeReaderOptionsクラスを使用すると、読み取りプロセスのあらゆる側面を設定できます。
using IronBarCode;
// Comment: configure the barcode reader for challenging conditions
var options = new BarcodeReaderOptions
{
// Comment: balance between scanning speed and accuracy on the device
Speed = ReadingSpeed.Balanced,
// Expect multiple barcodes per page or camera capture
ExpectMultipleBarcodes = true,
// Limit scanning to specific barcode types for faster results
ExpectBarcodeTypes = BarcodeEncoding.QRCode
| BarcodeEncoding.Code128
| BarcodeEncoding.DataMatrix,
// Auto-rotate barcodes captured at any camera angle
AutoRotate = true,
// Apply image filters to improve scanning in poor conditions
ImageFilters = new ImageFilterCollection
{
new SharpenFilter(), // Sharpen blurry camera captures
new ContrastFilter(1.5f) // Boost contrast for low light
}
};
// Comment: read barcodes from a sample image using configured options
var results = BarcodeReader.Read("warehouse_scan.jpg", options);
// Iterate and display results for the user
foreach (var barcode in results)
{
// Output each decoded barcode value from the scanner
Console.WriteLine($"Found: {barcode.Value}");
}
using IronBarCode;
// Comment: configure the barcode reader for challenging conditions
var options = new BarcodeReaderOptions
{
// Comment: balance between scanning speed and accuracy on the device
Speed = ReadingSpeed.Balanced,
// Expect multiple barcodes per page or camera capture
ExpectMultipleBarcodes = true,
// Limit scanning to specific barcode types for faster results
ExpectBarcodeTypes = BarcodeEncoding.QRCode
| BarcodeEncoding.Code128
| BarcodeEncoding.DataMatrix,
// Auto-rotate barcodes captured at any camera angle
AutoRotate = true,
// Apply image filters to improve scanning in poor conditions
ImageFilters = new ImageFilterCollection
{
new SharpenFilter(), // Sharpen blurry camera captures
new ContrastFilter(1.5f) // Boost contrast for low light
}
};
// Comment: read barcodes from a sample image using configured options
var results = BarcodeReader.Read("warehouse_scan.jpg", options);
// Iterate and display results for the user
foreach (var barcode in results)
{
// Output each decoded barcode value from the scanner
Console.WriteLine($"Found: {barcode.Value}");
}
Imports IronBarCode
' Comment: configure the barcode reader for challenging conditions
Dim options As New BarcodeReaderOptions With {
' Comment: balance between scanning speed and accuracy on the device
.Speed = ReadingSpeed.Balanced,
' Expect multiple barcodes per page or camera capture
.ExpectMultipleBarcodes = True,
' Limit scanning to specific barcode types for faster results
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128 Or BarcodeEncoding.DataMatrix,
' Auto-rotate barcodes captured at any camera angle
.AutoRotate = True,
' Apply image filters to improve scanning in poor conditions
.ImageFilters = New ImageFilterCollection From {
New SharpenFilter(), ' Sharpen blurry camera captures
New ContrastFilter(1.5F) ' Boost contrast for low light
}
}
' Comment: read barcodes from a sample image using configured options
Dim results = BarcodeReader.Read("warehouse_scan.jpg", options)
' Iterate and display results for the user
For Each barcode In results
' Output each decoded barcode value from the scanner
Console.WriteLine($"Found: {barcode.Value}")
Next
Speed プロパティは、速度と精度のトレードオフを制御します。大量のスキャンには ReadingSpeed.Faster を、難しいバーコードを最大限に検出するには ReadingSpeed.Detailed を使用してください。 ExpectBarcodeTypes設定は、スキャナSDKがチェックするフォーマットを制限することで、誤検出エラーを回避し、パフォーマンスを向上させます。 AutoRotate機能は、デバイスのカメラが不自然な角度で撮影したバーコードを自動的に補正し、SharpenFilterとContrastFilterは、暗い場所でのバーコードのスキャン精度を向上させます。 開発者は、CropArea プロパティを使用してズームスタイルの切り抜きを行い、スキャナーがキャプチャしたページの特定の領域に焦点を合わせるように設定することもできます。
リーダーの設定に関する詳細な手順については、 "画像からバーコードを読み取るためのガイド"および"BarcodeReaderOptions API リファレンス"を参照してください。 PDF文書からバーコードをデコードする必要がある開発者は、PDFバーコード読み取り方法も確認する必要があります。
モバイルバーコードソリューションの最適な活用事例とは?
XamarinのバーコードおよびQRコードスキャンソリューションは、様々な業界にわたる数十ものユースケースをサポートしています。 IronBarcodeがモバイルデバイス上で価値を提供するバーコードスキャナーとバーコードジェネレーターの両方を提供する最も一般的なシナリオは以下のとおりです。
*在庫および倉庫管理*:AndroidおよびiOSデバイスのユーザーは、製品や棚のバーコードをスキャンして在庫をリアルタイムで追跡し、手動入力のエラー率を減らし、スピードを向上させます。 倉庫管理アプリはどれも、高速で信頼性の高いバーコードスキャン機能の恩恵を受ける。 小売店のPOSシステム:レジでのQRコードスキャンにより、迅速な商品検索、クーポン利用、モバイル決済処理が可能になり、すべてアプリ画面上でユーザーに表示されます。 スキャナ機能は1次元フォーマットと2次元フォーマットの両方に対応しています。 物流と配送:AndroidおよびiOSデバイス群全体で、荷物のバーコードをスキャンして、ルート確認と配送確認を行います。 IronBarcodeは、スキャナーのページビュー上で、折り目がついていたり、部分的に隠れていたりするラベルからでもバーコードをデコードできます。 イベントチェックイン**:カンファレンスゲートのQRコードをデコードするXamarinアプリにより、参加者の認証が即座に行われます。従来の紙のチケットや手動でのアカウント検索は不要です。 アプリは各コードを1秒未満で読み取ります。 *医療:患者のリストバンド、薬剤ラベル、検査サンプルに付いているバーコードをモバイルデバイスでスキャンすることで、エラーを防ぎ、ユーザーによる正確な治療を保証します。 アプリ内の各読み取りページは、特定のバーコードの種類に合わせてカスタマイズできます。
IronBarcodeは、 .NET Standard、 .NET Core、 .NET MAUIなどのプラットフォーム全体にわたる包括的なバーコードスキャナとして、これらのXamarinバーコード使用例すべてをサポートします。 本番環境でXamarinバーコードソリューションを運用している開発者向けに、 IronBarcodeは継続的なサポート、定期的なアップデート、そして明確なライセンスオプションを提供します。 Xamarinから.NET MAUIへの移行がロードマップに含まれている場合、 IronBarcodeはコードの書き換えを必要とせず、シームレスに移行します。 手順を追った例については、 .NET MAUIバーコードスキャナーのチュートリアルを参照してください。
Microsoftが提供するXamarinプロジェクト移行ガイドでは、最新のクロスプラットフォームフレームワークへの移行手順が詳細に説明されています。 Stack Overflowのこちらの投稿では、Xamarinのバーコードに関する一般的な問題を取り上げており、コミュニティによる解決策への役立つリンクが掲載されています。また、 RedditのXamarin開発者コミュニティへのリンクでは、プラットフォームを横断したモバイルバーコード読み取り方法に関する追加の議論が掲載されています。
Xamarinのバーコードスキャンを今すぐ始めるには?
IronBarcodeは、Xamarinにおけるバーコード生成とバーコードスキャンを高速、高信頼性、そして開発者にとって使いやすいものにします。 30種類以上のバーコード形式に対応し、自動回転やカスタマイズ可能な前処理などの高度な機能を備え、コード行を簡潔かつ読みやすく保つ流暢なC#インターフェースを提供します。 シンプルなQRコードサンプルアプリの構築、PDFドキュメントからのバーコード処理、AndroidアプリやiOSアプリ向けの本格的なバーコードリーダーの構築など、どのようなソリューションであっても、 IronBarcodeは単一の、ドキュメントが充実したライブラリ内で全てを処理できます。 APIの各機能は、本番環境のアプリケーションにおいて、分かりやすさと使いやすさを考慮して設計されています。
XamarinプロジェクトでIronBarcodeをテストするには、無料トライアルに登録してください。 本番環境への移行準備が整ったら、ライセンスオプションをご確認ください。価格ページへのリンクから詳細をご覧いただけます(749ドルから)。購入後のサポートについては、開発者はライセンスアドオンページからサポート範囲をカスタマイズできます。
よくある質問
IronBarcode はXamarin アプリ開発をどのようにサポートしますか?
IronBarcode を使用すると、Xamarin アプリ開発者はわずか数行の C# コードでバーコードを作成、読み取り、デコードできます。Android、iOS、Windows プラットフォームをサポートし、モバイルアプリケーションでシームレスなバーコード機能を実現します。
IronBarcode はバーコードのスキャンと生成の両方に使用できますか?
はい、 IronBarcode はバーコード スキャナーとジェネレーターの両方の機能を備えているため、開発者は Xamarin アプリケーションでバーコードを簡単に作成して読み取ることができます。
IronBarcode はどのようなバーコードタイプをサポートしていますか?
IronBarcode は、Code 128、Data Matrix、QR コードなど、さまざまな種類のバーコードをサポートしており、さまざまなアプリケーションのニーズに柔軟に対応できます。
IronBarcode は.NET MAUIと互換性がありますか?
はい、 IronBarcodeは.NET MAUIにスムーズに移行できるように設計されており、Xamarin からの移行時に継続的なサポートと機能性を保証します。
既存の Xamarin アプリにとってIronBarcodeが重要なのはなぜですか?
Microsoft による Xamarin の公式サポートが終了する中、 IronBarcode は小売や物流などさまざまな業界の既存の Xamarin アプリでバーコード機能を維持するための信頼性の高いソリューションを提供します。
IronBarcode は物流と在庫管理にどのように役立ちますか?
IronBarcode は、バーコードを効率的に生成およびデコードし、追跡や在庫管理などのプロセスを合理化することで、物流と在庫管理を支援します。
IronBarcodeはどのプラットフォームをサポートしていますか?
IronBarcode はAndroid、iOS、Windows プラットフォームをサポートしており、クロスプラットフォームのバーコード アプリケーションに使用できる多目的ツールです。



