Samouczek komponentu .NET Barcode z użyciem IronBarcode
Komponent .NET do obsługi kodów kreskowych to biblioteka kodu zarządzanego, która pozwala generować i odczytywać kody kreskowe w aplikacjach C# za pomocą zaledwie kilku wierszy kodu. IronBarcode obsługuje wszystkie główne symbole — Code 128, QR, Data Matrix, EAN, UPC i inne — i działa na systemach Windows, Linux oraz macOS bez dodatkowych zależności środowiskowych.
Zainstaluj za pomocą NuGet i zacznij generować kody kreskowe w ciągu kilku minut:
Install-Package BarCode
Install-Package BarCode
Czym jest komponent BarCode .NET?
Komponent .NET do obsługi kodów kreskowych to biblioteka oprogramowania w postaci pakietu NuGet, która zapewnia funkcje generowania i odczytu kodów kreskowych za pośrednictwem przejrzystego interfejsu API. W przeciwieństwie do czcionek BARCODE, które wymagają ręcznego obliczania sum kontrolnych i stosowania skomplikówanych reguł formatowania, dedykowany komponent obsługuje całą logikę kodowania wewnętrznie.
Biblioteka IronBarcode udostępnia dwa główne punkty wejścia:
BarcodeWriter-- creates barcode images, PDFs, and HTML from text or numeric dataBarcodeReader-- scans images, PDFs, and multi-frame TIFFs to extract barcode values
Ta dwukierunkowa konstrukcja oznacza, że w tej samej bibliotece można zarówno drukować BARCODES na etykietach, jak i skanować je z dokumentów, co jest niezbędne do zarządzania zapasami, śledzenia dokumentów, integracji z Crystal Reports oraz automatyzacji przepływu danych.
Obsługiwane symbole obejmują:
- Kod liniowy 1D: Code 128, Code 39, Code 93, ITF-14, EAN-13, EAN-8, UPC-A, UPC-E
- Macierz 2D: QR, Data Matrix, PDF417, Aztec
- Warianty GS1: GS1-128, GS1 DataBar
Systemy produkcyjne zazwyczaj wykorzystują kod 128 do śledzenia produktów, ponieważ umożliwia on wydajne kodowanie danych alfanumerycznych. Aplikacje medyczne często wykorzystują kod Data Matrix do etykietowania leków, ponieważ dobrze się drukuje nawet w bardzo małych rozmiarach. Systemy kasowe w handlu detalicznym skanują barcodes EAN-13 i UPC-A przy kasie. Wybór odpowiedniej symboliki dla danego zastosowania jest jedną z pierwszych decyzji, jakie należy podjąć podczas integracji funkcji BarCode.
Jak zainstalować IronBarcode w projekcie .NET?
Instalacja IronBarcode zajmuje mniej niż dwie minuty przy użyciu menedżera pakietów NuGet w Visual Studio lub .NET CLI.
Konsola menedżera pakietów (Visual Studio):
Install-Package BarCode
Install-Package BarCode
.NET CLI:
dotnet add package BarCode
dotnet add package BarCode

Po zainstalowaniu pakietu dodaj przestrzeń nazw na początku każdego pliku, który korzysta z funkcji BARCODE:
using IronBarCode;
using IronBarCode;
Imports IronBarCode
IronBarcode jest przeznaczony dla platform .NET Framework 4.6.2 i nowszych, .NET Core 3.1 i nowszych oraz .NET 5 do .NET 10. Działa na systemach Windows, Linux i macOS, więc ten sam kod działa w kontenerach hostowanych w chmurze, na serwerach lokalnych i stacjach roboczych programistów bez konieczności konfiguracji specyficznej dla danej platformy.
W przypadku aplikacji .NET Core nie jest wymagańa rejestracja oprogramowania pośredniczącego. API wywołuje się bezpośrednio z kontrolerów, usług działających w tle lub stron Razor Pages. Aplikacje Windows Forms i WPF uzyskują dostęp w ten sam sposób — wystarczy dodać przestrzeń nazw i zacząć wywoływać metody.

Szczegółowe instrukcje instalacji, w tym konfiguracja kanału NuGet w trybie offline i ustawienia proxy, są dostępne w przewodniku IronBarcode "Pierwsze kroki".
Jak wygenerować obraz BarCode w języku C#?
Generowanie kodu kreskowego za pomocą IronBarcode wymaga trzech kroków: wyboru kodowania, ustawienia wartości i zapisania wyniku. Poniższy przykład tworzy BARCODE Code 128 i zapisuje go zarówno jako obraz PNG, jak i dokument PDF:
using IronBarCode;
// Create a Code 128 barcode encoding a product identifier
var barcode = BarcodeWriter.CreateBarcode("PRD-12345-2024", BarcodeEncoding.Code128);
// Set the output dimensions in pixels
barcode.ResizeTo(400, 100);
// Add human-readable text beneath the bars
barcode.AddBarcodeValueTextBelowBarcode();
// Export to PNG for screen display and label printing
barcode.SaveAsImage("product-barcode.png");
// Export to PDF for document embedding
barcode.SaveAsPdf("product-barcode.pdf");
using IronBarCode;
// Create a Code 128 barcode encoding a product identifier
var barcode = BarcodeWriter.CreateBarcode("PRD-12345-2024", BarcodeEncoding.Code128);
// Set the output dimensions in pixels
barcode.ResizeTo(400, 100);
// Add human-readable text beneath the bars
barcode.AddBarcodeValueTextBelowBarcode();
// Export to PNG for screen display and label printing
barcode.SaveAsImage("product-barcode.png");
// Export to PDF for document embedding
barcode.SaveAsPdf("product-barcode.pdf");
Imports IronBarCode
' Create a Code 128 barcode encoding a product identifier
Dim barcode = BarcodeWriter.CreateBarcode("PRD-12345-2024", BarcodeEncoding.Code128)
' Set the output dimensions in pixels
barcode.ResizeTo(400, 100)
' Add human-readable text beneath the bars
barcode.AddBarcodeValueTextBelowBarcode()
' Export to PNG for screen display and label printing
barcode.SaveAsImage("product-barcode.png")
' Export to PDF for document embedding
barcode.SaveAsPdf("product-barcode.pdf")
The ResizeTo() method sets pixel dimensions precisely, which matters when you are printing labels at a specific DPI. The AddBarcodeValueTextBelowBarcode() call adds human-readable text under the bars, making manual verification easier in warehouse and retail environments.
Formaty wyjściowe BarCode


IronBarcode eksportuje do formatów PNG, JPEG, GIF, TIFF, BMP, PDF, HTML oraz ciągów znaków base64. Format base64 jest szczególnie przydatny do osadzania BARCODE'ów w odpowiedziąch API, które frontend renderuje dynamicznie bez zapisywania plików na dysku.
Jak wygenerować kod QR w języku C#?
For QR codes, IronBarcode provides the QRCodeWriter class with built-in support for error correction levels and module size control:
using IronBarCode;
// Generate a QR code from a URL with 500px dimensions
var qrCode = QRCodeWriter.CreateQrCode("https://example.com/product/12345", 500);
// Save the QR code to a PNG file
qrCode.SaveAsImage("product-qr.png");
using IronBarCode;
// Generate a QR code from a URL with 500px dimensions
var qrCode = QRCodeWriter.CreateQrCode("https://example.com/product/12345", 500);
// Save the QR code to a PNG file
qrCode.SaveAsImage("product-qr.png");
Imports IronBarCode
' Generate a QR code from a URL with 500px dimensions
Dim qrCode = QRCodeWriter.CreateQrCode("https://example.com/product/12345", 500)
' Save the QR code to a PNG file
qrCode.SaveAsImage("product-qr.png")
Kody QR mogą kodować adresy URL, zwykły tekst, dane kontaktowe vCard, dane logowania do sieci Wi-Fi oraz dowolne sekwencje bajtów. Strona z przykładami generowania BarCodes obejmuje dodatkowe scenariusze kodowania, w tym Data Matrix i PDF417.
Jak odczytywać BarCodes z obrazów?
Odczytywanie BarCode'ów z obrazu jest tak proste, jak ich zapisywanie. The BarcodeReader.Read() method accepts a file path, Stream, Bitmap, or IronSoftware.Drawing.AnyBitmap, and returns a BarcodeResults collection:
using IronBarCode;
// Read all barcodes from a scanned document image
BarcodeResults results = BarcodeReader.Read("scanned-document.png");
// Iterate over every detected barcode
foreach (BarcodeResult result in results)
{
string value = result.Value;
BarcodeEncoding type = result.BarcodeType;
Console.WriteLine($"Detected {type}: {value}");
}
using IronBarCode;
// Read all barcodes from a scanned document image
BarcodeResults results = BarcodeReader.Read("scanned-document.png");
// Iterate over every detected barcode
foreach (BarcodeResult result in results)
{
string value = result.Value;
BarcodeEncoding type = result.BarcodeType;
Console.WriteLine($"Detected {type}: {value}");
}
Imports IronBarCode
' Read all barcodes from a scanned document image
Dim results As BarcodeResults = BarcodeReader.Read("scanned-document.png")
' Iterate over every detected barcode
For Each result As BarcodeResult In results
Dim value As String = result.Value
Dim type As BarcodeEncoding = result.BarcodeType
Console.WriteLine($"Detected {type}: {value}")
Next
Czytnik automatycznie przetwarza obrazy, aby skorygować typowe problemy związane ze skanowaniem: obrót, przekrzywienie, szumy, niski kontrast i zniekształcenia perspektywiczne. Oznacza to, że można przekazać surowe dane wyjściowe skanera bezpośrednio, bez konieczności ich samodzielnego przetwarzania.
Skanowanie z prawdziwego dokumentu

Wynik czytania

How Do You Configure Barcode Reading Options?
For high-volume or challenging scanning scenarios, BarcodeReaderOptions gives you fine-grained control over the reading algorithm:
using IronBarCode;
var options = new BarcodeReaderOptions
{
// Balance accuracy and processing time
Speed = ReadingSpeed.Balanced,
// Detect multiple barcodes in one pass
ExpectMultipleBarcodes = true,
// Limit the search to 1D formats for faster processing
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
};
// Read from a multi-page PDF warehouse inventory report
var results = BarcodeReader.Read("warehouse-inventory.pdf", options);
using IronBarCode;
var options = new BarcodeReaderOptions
{
// Balance accuracy and processing time
Speed = ReadingSpeed.Balanced,
// Detect multiple barcodes in one pass
ExpectMultipleBarcodes = true,
// Limit the search to 1D formats for faster processing
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
};
// Read from a multi-page PDF warehouse inventory report
var results = BarcodeReader.Read("warehouse-inventory.pdf", options);
Imports IronBarCode
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
}
' Read from a multi-page PDF warehouse inventory report
Dim results = BarcodeReader.Read("warehouse-inventory.pdf", options)
Setting ExpectBarcodeTypes to match the formats you actually expect improves throughput because the reader skips patterns that cannot match. The Speed property ranges from Faster (best for clean, high-quality images) to ExtremeDetail (best for damaged or low-resolution sources). The barcode reading documentation covers additional options including multi-threading and region-of-interest scanning.
How Do You Customize Barcode Appearance?
IronBarcode lets you control every visual aspect of a generated barcode before saving it. You can set colors, fonts, margins, and annotation text programmatically. This is useful when generating barcodes for branded labels or regulated industries where label layout follows strict specifications.
The API follows a fluent-style pattern: create the barcode, call style methods, then save. All style properties affect the output immediately and do not require a separate render step. See the styling and annotation examples for the full list of available properties.
How Do You Handle Barcodes in PDF Documents?
IronBarcode reads barcodes embedded in PDF files the same way it reads image files. Pass a PDF path to BarcodeReader.Read() and the library extracts barcodes from every page automatically. This is valuable for accounts payable workflows where invoice PDFs contain GS1-128 barcodes, and for logistics systems where shipping manifests are distributed as PDF attachments.
You can also write barcodes directly into PDF pages using IronBarcode alongside IronPDF for document generation. A common pattern is to generate a shipping label PDF that contains both a human-readable address block and a scannable Code 128 barcode for the tracking number.
For further reading on PDF barcode workflows, the IronBarcode tutorials section provides end-to-end examples covering invoice processing, batch label printing, and document archiving.
How Do You Integrate Barcodes into ASP.NET Core APIs?
Returning a barcode image from an ASP.NET Core controller endpoint is a common requirement for web portals that display dynamic labels. IronBarcode's base64 output makes this straightforward:
using IronBarCode;
// In an ASP.NET Core controller action
public IActionResult GetBarcodeImage(string productId)
{
var barcode = BarcodeWriter.CreateBarcode(productId, BarcodeEncoding.Code128);
barcode.ResizeTo(400, 100);
barcode.AddBarcodeValueTextBelowBarcode();
// Return the barcode as a PNG image response
byte[] imageBytes = barcode.ToJpegBinaryData();
return File(imageBytes, "image/jpeg");
}
using IronBarCode;
// In an ASP.NET Core controller action
public IActionResult GetBarcodeImage(string productId)
{
var barcode = BarcodeWriter.CreateBarcode(productId, BarcodeEncoding.Code128);
barcode.ResizeTo(400, 100);
barcode.AddBarcodeValueTextBelowBarcode();
// Return the barcode as a PNG image response
byte[] imageBytes = barcode.ToJpegBinaryData();
return File(imageBytes, "image/jpeg");
}
Imports IronBarCode
' In an ASP.NET Core controller action
Public Function GetBarcodeImage(productId As String) As IActionResult
Dim barcode = BarcodeWriter.CreateBarcode(productId, BarcodeEncoding.Code128)
barcode.ResizeTo(400, 100)
barcode.AddBarcodeValueTextBelowBarcode()
' Return the barcode as a PNG image response
Dim imageBytes As Byte() = barcode.ToJpegBinaryData()
Return File(imageBytes, "image/jpeg")
End Function
This approach works with any frontend framework. The browser receives a standard image response and displays it in an <img> tag. For high-traffic endpoints, generate barcodes once and cache the byte array, since the same product ID always produces the same barcode image.
The IronBarcode API reference documents all available methods including streaming output, which avoids allocating large byte arrays for very high-resolution barcodes.
How Does IronBarcode Handle Barcode Validation and Error Correction?
Barcode standards define strict encoding rules and checksum requirements. Code 128 uses a weighted modulo-103 checksum. EAN-13 uses modulo-10. QR codes embed Reed-Solomon error correction that allows partial data recovery even when up to 30% of the barcode is obscured or damaged.
IronBarcode enforces these rules automatically. When you call BarcodeWriter.CreateBarcode(), the library validates that the data fits the symbology's character set and length constraints, then calculates and appends the correct checksum without any additional steps from your code. This prevents generating invalid barcodes that scanners will reject.
On the reading side, the library applies error correction during decoding, which means it can often recover the correct value from a barcode that is partially torn, smudged, or printed at low resolution. This behavior is particularly important for GS1 barcode standards compliance in retail and logistics.
For a deeper look at how barcode error correction works at the specification level, the ISO/IEC barcode standards documentation provides the authoritative technical reference.
What Are Common Barcode Integration Scenariuszs?
| Scenariusz | Symbology | Key IronBarcode Feature |
|---|---|---|
| Retail point-of-sale | EAN-13, UPC-A | BarcodeEncoding.EAN13, PDF export |
| Warehouse inventory | Code 128, ITF-14 | ExpectMultipleBarcodes = true |
| Healthcare labeling | Data Matrix, GS1-128 | Small-size printing, high DPI export |
| Document tracking | PDF417, Code 39 | PDF reading, multi-page support |
| Mobile product lookup | Kod QR | QRCodeWriter.CreateQrCode() |
| Shipping labels | Code 128, GS1-128 | Label-size PDF output, text annotation |
Each scenario benefits from different configuration choices. The IronBarcode examples gallery provides runnable code for all of the scenarios above.
Jakie są Twoje kolejne kroki?
Integrating a barcode .NET component turns what would otherwise be a weeks-long custom development effort into an afternoon of configuration. IronBarcode handles encoding rules, checksums, image preprocessing, and error correction so your team can focus on the business logic that surrounds barcode workflows rather than the barcode mechanics themselves.
To move forward:
- Install the package:
dotnet add package BarCodeorInstall-Package BarCodein the Package Manager Console - Try the quickstart: The barcode quickstart example walks through generation and reading in under 20 lines of code
- Explore symbologies: The supported barcode types reference lists all encoding formats with usage guidance
- Review pricing: IronBarcode licensing options cover single-developer, team, and OEM redistribution use cases
- Start a free trial: Download a 30-day free trial license to evaluate the full feature set in your own application
For questions about enterprise licensing, high-volume deployments, or technical integration challenges, the IronBarcode support team is available to help.
External references for barcode standards and specifications:
- GS1 barcode standards -- the global authority on retail and logistics barcode specifications
- ISO/IEC barcode standards committee -- international standards for 1D and 2D barcode symbologies
- C# barcode Q&A on Stack Overflow -- community discussions on barcode implementation in .NET
Często Zadawane Pytania
Czym jest komponent .NET do obsługi kodów kreskowych BarCode?
Komponent .NET do obsługi kodów kreskowych to biblioteka oprogramowania, która umożliwia programistom integrację generowania i skanowania kodów kreskowych z aplikacjami .NET, automatycznie obsługując reguły kodowania, sumy kontrolne i wstępne przetwarzanie obrazów.
W jaki sposób IronBarcode może pomóc w aplikacjach .NET?
IronBarcode udostępnia komponent .NET do generowania i odczytu kodów kreskowych za pośrednictwem prostego interfejsu API, co ułatwia dodawanie funkcji kodów kreskowych do aplikacji C# bez konieczności ręcznego wdrażania algorytmów kodowania.
Jakie rodzaje kodów kreskowych można generować za pomocą IronBarcode?
IronBarcode obsługuje formaty Code 128, Code 39, Code 93, ITF-14, EAN-13, EAN-8, UPC-A, UPC-E, QR Code, Data Matrix, PDF417, Aztec oraz warianty GS1.
Dlaczego warto używać komponentu do obsługi kodów kreskowych zamiast tworzyć własne rozwiązanie?
Professional BarCode component automatically handles sum control calculation, error correction, image preprocessing, and multi-format support, which reduces development time and reduces the risk of generating incorrect BarCodes.
Czy IronBarcode nadaje się do zadań związanych z automatyzacją danych?
Tak, IronBarcode doskonale nadaje się do automatyzacji danych. Odczytuje kody kreskowe z obrazów i plików PDF oraz integruje się bezpośrednio z usługami działającymi w tle, zaplanowanymi zadaniami i interfejsami API .NET Core.
Czy IronBarcode może służyć do śledzenia dokumentów?
Tak. IronBarcode odczytuje kody kreskowe z wielostronicowych plików PDF i wieloklatkowych plików TIFF, dzięki czemu sprawdza się w procesach śledzenia dokumentów w logistyce, księgowości i zarządzaniu dokumentacją.
Jakie wersje .NET obsługuje IronBarcode?
IronBarcode obsługuje platformy .NET Framework 4.6.2 i nowsze, .NET Core 3.1 i nowsze oraz .NET 5 do .NET 10, działające w systemach Windows, Linux i macOS.
W jaki sposób IronBarcode usprawnia systemy zarządzania zapasami?
IronBarcode zapewnia niezawodne generowanie kodów kreskowych oraz skanowanie wielu kodów kreskowych z obrazów i plików PDF, umożliwiając szybkie i dokładne śledzenie zapasów w magazynach i sklepach detalicznych.




