Zum Fußzeileninhalt springen
MIT ANDEREN KOMPONENTEN VERGLEICHEN
Ein Vergleich zwischen IronBarcode und den ZXing.NET Bibliotheken

Ein Vergleich zwischen IronBarcode und ZXing.NET

Ein Barcode-Scanner ist möglicherweise nicht immer für unsere Anwendungen geeignet. Möglicherweise haben Sie bereits ein digitales Bild des Barcodes und möchten wissen, was es im englischen Text darstellt. Darüber hinaus liest dieser Scanner nur 1-D-Barcodes, die eine begrenzte Datenmenge enthalten und nur in der Windows RT-Klassenbibliothek verwendet werden können. 2-D-Barcodes (auch als QR-Codes bekannt) sind mittlerweile verbreitet und können wesentlich mehr Informationen speichern.

Eine C#-basierte Anwendung kann erstellt werden, um Barcodes mithilfe einfacher API-Aufrufe und einiger Codierungsschritte zu lesen. Eine .NET-unterstützte Anwendung läuft auf Windows, macOS oder Linux, ohne auf Drittanbieter-Tools oder -APIs angewiesen zu sein.

Dieser Artikel vergleicht die beiden leistungsstärksten .NET Core-App-Bibliotheken zum programmgesteuerten Lesen von Barcodes. Diese beiden Bibliotheken sind IronBarcode und ZXing.NET. Wir werden sehen, was IronBarcode leistungsstärker und robuster macht als ZXing.NET.


class="hsg-featured-snippet">

Wie man Barcode in C# mit Zxing generiert

  1. Installieren Sie die C#-Bibliothek zur Barcode-Generierung
  2. Erstellen Sie ein neues Objekt aus der BarcodeWriterPixelData-Klasse, um den Barcode anzupassen
  3. Legen Sie den Barcode-Typ mit der Format-Eigenschaft fest
  4. Instanziieren Sie die QrCodeEncodingOptions-Klasse, um Höhe, Breite und Rand weiter anzupassen
  5. Generieren Sie den Barcode in C# mit der Write-Methode des Objekts aus Schritt 2

Was ist ZXing.NET

ZXing.NET ist eine Bibliothek, die Barcodes (wie QR-Code, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar) dekodiert und generiert. ZXing, was für "zebra crossing" steht, ist eine auf Java basierende, Open-Source-Bibliothek, die eine Vielzahl von 1D- und 2D-Barcode-Formaten unterstützt.

Seine wesentlichen Merkmale sind wie folgt:

  • Es hat die Fähigkeit, URLs, Kontaktdaten, Kalenderereignisse und mehr zu speichern
  • Es ist für Java SE-Anwendungen zugeschnitten
  • Es ermöglicht die Integration von Barcode-Scannern über Intent
  • Es ist eine unkomplizierte Google Glass-App

Was ist IronBarcode

IronBarcode ist eine C#-Bibliothek, die es Programmierern ermöglicht, Barcodes zu lesen und zu generieren. Als führende Barcode-Bibliothek unterstützt IronBarcode eine Vielzahl von eindimensionalen und zweidimensionalen Barcodes, einschließlich dekorierter (farbiger und gebrandeter) QR-Codes. Es unterstützt .NET Standard und Core-Versionen 2 und höher, was die plattformübergreifende Nutzung auf Azure, Linux, macOS, Windows und Web ermöglicht. IronBarcode ist eine bekannte Klassenbibliothek oder Komponente für das .NET-System, die C#-, VB.NET- und F#-Entwicklern die Arbeit mit standardisierten Programmiersprachen ermöglicht. Es ermöglicht Kunden, Scanner-Tags zu durchsuchen und neue standardisierte Labels zu erstellen. Es funktioniert außergewöhnlich gut mit 2D-Barcodes und anderen 3D-standardisierten Barcodes.

IronBarcode unterstützt jetzt 2D-Barcodes. Es bietet Funktionen zur Optimierung der Farbgebung, Gestaltung und Pixelierung dieser Codes und die Möglichkeit, Logos hinzuzufügen, um sie in Druck- oder Werbematerial zu verwenden. Diese Bibliothek kann auch verzerrte und deformierte Barcodes lesen, was andere Barcode-Software möglicherweise nicht lesen kann.

Installation von IronBarcode und ZXing.NET

Installation von ZXing.NET

Um die ZXing.NET-Bibliothek zu verwenden, installieren Sie die folgenden zwei Pakete in Ihrer ASP.NET Core-Anwendung mit der NuGet-Paket-Manager-Konsole:

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

Alternativ können Sie ZXing.NET in Ihrem Projekt über den NuGet-Paket-Manager installieren. Gehen Sie dazu zu Tools > NuGet-Paket-Manager > NuGet-Pakete für Lösungen verwalten..., wechseln Sie dann zur "Durchsuchen"-Registerkarte und suchen Sie nach "ZXing.NET".

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 1: ASP.NET-Webanwendung

class="content__image-caption">ASP.NET-Webanwendung

Installation von IronBarcode

Installieren Sie IronBarcode mit dem NuGet-Paket-Manager oder indem Sie die DLL direkt von der Produktwebsite herunterladen. Der IronBarcode-Namensraum enthält alle IronBarcode-Klassen.

IronBarcode kann mit dem NuGet-Paket-Manager für Visual Studio installiert werden: Der Paketname ist "Barcode".

Install-Package BarCode

Erstellen eines 2D-Barcodes

Verwendung von ZXing.NET

Erstellen Sie zunächst einen neuen Ordner namens 'qrr' im Stammordner der Projektdatei.

Wir werden dann QR-Dateien erstellen und die Bildsystemdateien im 'qrr'-Ordner speichern.

Fügen Sie im Controller die GenerateFile()-Methode wie im Quellcode unten gezeigt hinzu.

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);
}
Public Function GenerateFile() As ActionResult
	Return View()
End Function

<HttpPost>
Public Function GenerateFile(ByVal qrText As String) As ActionResult
	Dim byteArray() As Byte
	Dim width = 250 ' width of the QR Code
	Dim height = 250 ' height of the QR Code
	Dim margin = 0

	' BarcodeWriterPixelData acts as a QR code generator
	Dim qrCodeWriter = New ZXing.BarcodeWriterPixelData With {
		.Format = ZXing.BarcodeFormat.QR_CODE,
		.Options = New QrCodeEncodingOptions With {
			.Height = height,
			.Width = width,
			.Margin = margin
		}
	}
	Dim 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 bitmap = New System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
		Using ms = New MemoryStream()
			Dim 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)
			End Try

			' Save to folder
			Dim fileGuid As String = 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()
		End Using
	End Using
	Return View(byteArray)
End Function
$vbLabelText   $csharpLabel

Die einzige verbleibende Änderung besteht darin, die QR-Code-Datei im 'qrr'-Ordner zu speichern. Dies wird mit den beiden Codezeilen unten durchgeführt.

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);
Dim fileGuid As String = Guid.NewGuid().ToString().Substring(0, 4)
bitmap.Save(Server.MapPath("~/qrr") & "/file-" & fileGuid & ".png", System.Drawing.Imaging.ImageFormat.Png)
$vbLabelText   $csharpLabel

Als nächstes müssen Sie die GenerateFile-Ansicht erstellen und den folgenden Code darin einfügen. Die GenerateFile-Ansicht ist identisch mit der Indexansicht.

@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))" />
    }
}
model Function [using](Html.BeginForm ByVal As (Nothing, Nothing, FormMethod.Post)) As Byte()
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <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>
	"qrText" /> </td> </tr> (Of tr) <td colspan="2"> (Of button) Submit</button> </td> </tr> </tbody> </table>
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <table> <tbody> <tr> <td> <label> Enter text for creating QR Code</label> </td> <td> <input type="text" name="qrText" /> </td> </tr> <tr> <td colspan
	"text" name="qrText" /> </td> </tr> (Of tr) <td colspan
	(Of table) (Of tbody) (Of tr) (Of td) (Of label) Enter text for creating QR Code</label> </td> (Of td) <input type="text" name
End Function
@
If True Then
	If Model IsNot Nothing Then
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
		(Of h3) QR Code Successfully Generated</h3> <img src="@String.Format("data:image/png
		base64,
		If True Then
			0
		End If
		", Convert.ToBase64String(Model))" />
	End If
End If
$vbLabelText   $csharpLabel

Geben Sie einen beliebigen Wert in das Textfeld ein und klicken Sie auf die Schaltfläche 'Absenden'. Der QR-Code wird generiert und als .PNG-Datei im 'qrr'-Ordner gespeichert.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 2: QR-Code-Generator

class="content__image-caption">QR-Code-Generator

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 3: QR-Code-Dateien angezeigt

class="content__image-caption">QR-Code-Dateien angezeigt

Unterstützte Barcode-Formate

IronBarcode unterstützt eine große Auswahl häufig verwendeter Barcode-Formate, darunter:

  • QR-Codes mit Logos und Farben (einschließlich dekorierter und gebrandeter Codes)
  • Multi-Format-Barcodes einschließlich Aztec, Datenmatrix, CODE 93, CODE 128, RSS Expanded Databar, UPS MaxiCode und USPS, IMB (OneCode) Barcodes
  • RSS-14 und PDF-417 gestapelte lineare Barcodes
  • UPCA, UPCE, EAN-8, EAN-13, Codabar, ITF, MSI und Plessey sind traditionelle numerische Barcode-Formate.

Barcode erstellen und speichern

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);
Imports IronBarCode
' Create a barcode and save it in various formats
Private 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
Dim MyBarCodeImage As System.Drawing.Image = MyBarCode.Image
Dim MyBarCodeBitmap As System.Drawing.Bitmap = MyBarCode.ToBitmap()
Dim DataURL As String = MyBarCode.ToDataUrl()
Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag()
Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData()

' Save barcode in PDF stream
Using PdfStream As System.IO.Stream = MyBarCode.ToPdfStream()
	' The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
End Using

' Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50)
$vbLabelText   $csharpLabel

Andererseits ist ZXing eine auf Java basierende Open-Source-Bildverarbeitungsbibliothek für 1D/2D-Barcodes. UPC-A, UPC-E, EAN-8, Code 93, Code 128, QR-Code, Datenmatrix, Aztec, PDF 417 und andere Barcode-Formate werden unterstützt.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 4: Unterstützte Barcode-Formate

class="content__image-caption">Unterstützte Barcode-Formate

QR-Code-Dateien mit IronBarcode erstellen

Um QR-Codes mit IronBarcode zu erstellen, können wir die QRCodeWriter-Klasse anstelle der BarcodeWriter-Klasse verwenden. Diese Klasse führt einige neue und interessante Funktionen zur Erstellung von QR-Codes ein. Es ermöglicht uns, das QR-Fehlerkorrekturlevel einzustellen, sodass Sie ein Gleichgewicht zwischen Größe und Lesbarkeit Ihres QR-Codes erreichen können.

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");
Imports IronBarCode
' Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png")
$vbLabelText   $csharpLabel

Die Fehlerkorrektur ermöglicht es uns zu bestimmen, wie einfach es sein wird, einen QR-Code in realen Situationen zu lesen. Höhere Fehlerkorrekturstufen führen zu größeren QR-Codes mit mehr Pixeln und Komplexität. Im untenstehenden Bild sehen wir die Anzeige der QR-Code-Datei.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 5: Unterstützte Barcode-Formate

class="content__image-caption">QR-Code-Bild

Wir beginnen mit der Angabe des Barcode-Werts und des Barcode-Formats aus dem IronBarcode.BarcodeWriterEncoding-Enum. Wir können es dann als Bild, ein System.Drawing.Image oder ein Bitmap-Code-Objekt speichern.

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");
Imports IronBarCode
Imports System.Diagnostics

' Generate a simple BarCode image and save as PNG using the following namespaces
Private MyBarCode As GeneratedBarcode = 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")
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 6: Barcode-Bild in C# Beispiel erstellen

class="content__image-caption">Barcode-Bild in C# Beispiel erstellen

IronBarcode unterstützt auch das Stilifizieren von QR-Codes, wie z.B. ein Logo-Grafikbild, das genau in der Mitte des Bildes platziert und auf ein Raster zugeschnitten wird. Es kann auch eingefärbt werden, um zu einer bestimmten Marke oder grafischen Identität zu passen.

Erstellen Sie zum Testen ein Logo im folgenden Codebeispiel und sehen Sie, wie einfach es ist, die QRCodeWriter.CreateQRCodeWithLogo-Methode zu verwenden.

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);
Imports IronBarCode

' Adding a Logo
Private MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500)
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 7: QR-Code mit Logo-Bild erstellen

class="content__image-caption">QR-Code mit Logo-Bild erstellen

Schließlich speichern wir den erzeugten QR-Code als PDF-Datei. Zur Ihrer Bequemlichkeit speichert die abschließende Codezeile den QR-Code als HTML-Datei.

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");
Imports IronBarCode

' Adding a Logo
Private 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")
$vbLabelText   $csharpLabel

Unten sehen wir, wie man mit nur einer Codezeile einen Barcode erstellt, stilisiert und exportiert.

IronBarcode enthält eine flüssige API, die System.Linq ähnelt. Wir erstellen einen Barcode, setzen seine Ränder und exportieren ihn in einem einzigen Aufruf in ein Bitmap, indem wir Methodenaufrufe verketten. Dies kann sehr nützlich sein und macht den Code einfacher lesbar.

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();
Imports IronBarCode
Imports System.Drawing

' Fluent API for Barcode image generation
Private MyValue As String = "https://ironsoftware.com/csharp/barcode"
Private BarcodeBmp As Bitmap = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417).ResizeTo(300, 200).SetMargins(100).ToBitmap()
$vbLabelText   $csharpLabel

Infolgedessen erscheint ein System.Drawing.Image eines PDF417-Barcodes, wie unten dargestellt.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 8: Einfaches, flüssiges PDF417-Barcode-Generierung in C#

class="content__image-caption">Einfaches, flüssiges PDF417-Barcode-Generierung in C#

QR-Code-Dateien lesen

Lesen von QR-Codes mit IronBarcode

Das Lesen eines Barcodes oder QR-Codes ist ein Kinderspiel, wenn Sie die IronBarcode-Klassenbibliothek zusammen mit dem .NET-Barcode-Reader verwenden. In unserem ersten Beispiel sehen wir, wie man einen Barcode mit nur einer Codezeile lesen kann.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 9: Code128-Barcode-Bild, das mit C# gescannt werden soll

class="content__image-caption">Code128-Barcode-Bild, das mit C# gescannt werden soll

Wir können den Barcode-Wert, das Bild, den Codierungstyp und die Binärdaten (falls vorhanden) abrufen und dann in die Konsole ausgeben.

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);
}
Imports IronBarCode
Imports System

' Read a barcode or QR code from an image
Private Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png")
If Result IsNot Nothing AndAlso Result.Text = "https://ironsoftware.com/csharp/barcode/" Then
	Console.WriteLine("GetStarted was a success.  Read Value: " & Result.Text)
End If
$vbLabelText   $csharpLabel

Lesen von Barcodes in PDFs

Wir werden uns ansehen, wie man ein gescanntes PDF-Dokument liest und alle eindimensionalen Barcodes in wenigen Codezeilen findet.

Wie Sie sehen können, ähnelt es stark dem Lesen eines einzelnen Barcodes aus einem einzigen Dokument, mit dem Unterschied, dass wir nun wissen, auf welcher Seitenzahl der Barcode gefunden wurde.

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);
}
Imports IronBarCode
Imports System
Imports 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
Private PDFResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdf("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
$vbLabelText   $csharpLabel

Sie erhalten Result-Daten mit allen Bitmap-Barcodes im PDF.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 10: Lesen der im PDF gespeicherten Barcodes Ergebnisse

class="content__image-caption">Lesen der im PDF gespeicherten Barcodes Ergebnisse

Lesen von Barcodes aus GIF und 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
}
Imports IronBarCode
Imports System

' Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
Private MultiFrameResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels)
For Each PageResult In MultiFrameResults
	' Process each page result
Next PageResult
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 11: Lesen von Barcodes aus einem mehrseitigen TIFF-Bild

class="content__image-caption">Lesen von Barcodes aus einem mehrseitigen TIFF-Bild

Das folgende Beispiel zeigt, wie man QR-Codes und PDF-417-Barcodes aus einem gescannten PDF liest. Wir haben ein angemessenes Level der Barcode-Drehungskorrektur und Barcode-Bildkorrektur eingestellt, um das Dokument leicht zu säubern, ohne signifikante Leistungsstrafen zu verursachen.

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;
    //...
}
Imports IronBarCode
Imports System

' PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
Private ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels)

' Work with the results
For Each PageResult In ScanResults
	Dim Value As String = PageResult.Value
	'...
Next PageResult
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 12: Lesen von Barcodes aus einem gescannten PDF-Dokument

class="content__image-caption">Lesen von Barcodes aus einem gescannten PDF-Dokument

Lesen von KORRUPTIERTEN QR-Codes aus Bitmap-Bildern

Das folgende Beispiel zeigt, dass diese C#-Barcode-Bibliothek sogar ein beschädigtes Barcode-Thumbnail lesen kann.

Die Korrektur der Barcode-Thumbnail-Größe erfolgt automatisch. IronBarcode in C# macht eine Datei lesbar.

Die Leser-Methoden erkennen automatisch Barcode-Bilder, die zu klein sind, um ein legitimer Barcode zu sein, und skalieren sie hoch. Sie beseitigen alle digitalen Störungen, die mit der Arbeit mit Thumbnails verbunden sind, und machen sie wieder lesbar.

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);
Imports IronBarCode

' Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
Private SmallResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128)
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 13: Automatische Barcode-Thumbnail-Größenkorrektur

class="content__image-caption">Automatische Barcode-Thumbnail-Größenkorrektur

Lesen von Barcodes aus unvollkommenen Bildern

In realen Szenarien möchten wir möglicherweise Barcodes aus unvollkommenen Bildern lesen. Es könnten verzerrte Bilder oder Fotografien mit digitalem Rauschen sein. Dies wäre mit den meisten Open-Source-.NET-Bibliotheken zur Barcode-Generierung und -Lesung unmöglich. IronBarcode hingegen macht das Lesen von Barcodes aus unvollkommenen Bildern einfach.

Wir werden jetzt die ReadASingleBarcode-Methode betrachten. Mit seinem RotationCorrection-Parameter versucht IronBarcode, Barcodes aus unvollkommenen digitalen Mustern zu entkrümmen und zu lesen.

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);
Imports IronBarCode
Imports System
Imports 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
Private PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels)
Private Value As String = PhotoResult.Value
Private Img As System.Drawing.Bitmap = PhotoResult.BarcodeImage
Private BarcodeType As BarcodeEncoding = PhotoResult.BarcodeType
Private Binary() As Byte = PhotoResult.BinaryValue
Console.WriteLine(PhotoResult.Value)
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 14: Lesen eines Barcodes von einer Telefonkamera

class="content__image-caption">Lesen eines Barcodes von einer Telefonkamera

IronBarcode kann auch mehrere Barcodes gleichzeitig lesen. Wir erhalten bessere Ergebnisse von IronBarcode, wenn wir eine Liste von Dokumenten erstellen und den Barcode-Reader verwenden, um mehrere Dokumente zu lesen. Die ReadBarcodesMultithreaded-Methode für den Barcode-Scanner-Prozess verwendet mehrere Threads und potenziell alle Kerne Ihrer CPU, was exponentiell schneller sein kann als das Lesen von Barcodes einzeln.

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;
    //...
}
Imports IronBarCode

' The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
Private ListOfDocuments = { "Image1.png", "image2.JPG", "image3.pdf" }
Private BatchResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments)

' Work with the results
For Each Result In BatchResults
	Dim Value As String = Result.Value
	'...
Next Result
$vbLabelText   $csharpLabel

Lesen und Dekodieren von QR-Codes mit ZXing.NET

Um die QR-Code-Dateien zu lesen, fügen Sie Ihrer Steuerung die Aktionsmethode ViewFile hinzu, wie unten gezeigt.

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);
}
Public Function ViewFile() As ActionResult
	Dim fileData As New List(Of KeyValuePair(Of String, String))()
	Dim data As KeyValuePair(Of String, String)

	Dim files() As String = Directory.GetFiles(Server.MapPath("~/qrr"))
	For Each file As String In files
		' Create a barcode reader instance
		Dim reader As IBarcodeReader = New BarcodeReader()

		' Load a bitmap
		Dim barcodeBitmap = CType(Image.FromFile(Server.MapPath("~/qrr") & "/" & Path.GetFileName(file)), Bitmap)

		' Detect and decode the barcode inside the bitmap
		Dim result = reader.Decode(barcodeBitmap)

		' Do something with the result
		data = New KeyValuePair(Of String, String)(result.ToString(), "/QR/" & Path.GetFileName(file))
		fileData.Add(data)
	Next file
	Return View(fileData)
End Function
$vbLabelText   $csharpLabel
class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 15: QR-Code lesen und dekodieren

class="content__image-caption">QR-Code lesen und dekodieren

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 16: Dekodierter QR-Code

class="content__image-caption">Dekodierter QR-Code

Dekodierung eines Barcodes in einem Bitmap

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;
}
Imports ZXing
Imports System.Drawing

' Create a barcode reader instance
Private reader As New BarcodeReader()

' Load a bitmap
Private barcodeBitmap = CType(Image.FromFile("C:\sample-barcode-image.png"), Bitmap)

' Detect and decode the barcode inside the bitmap
Private result = reader.Decode(barcodeBitmap)

' Do something with the result
If result IsNot Nothing Then
	txtDecoderType.Text = result.BarcodeFormat.ToString()
	txtDecoderContent.Text = result.Text
End If
$vbLabelText   $csharpLabel

ZXing Decoder Online

ZXing Decoder Online ist ein Barcode- und QR-Code-Scanner, der online verfügbar ist und das Dekodieren unterstützt. Laden Sie ein PNG- oder ein anderes Format des QR-Code-Bildes hoch, und es wird mit dem Dekodieren begonnen. Ebenso können Sie einen QR-Code für beliebige Daten generieren. Meistens sind diese Informationen eine URL oder ein Text, den Sie in einen QR-Code kodieren möchten.

Navigieren Sie zur ZXing Decoder-Website.

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 17: Dekodierter QR-Code

class="content__image-caption">ZXing Decoder-Website

class="content-img-align-center"> Ein Vergleich zwischen IronBarcode und ZXing.NET, Abbildung 18: Dekodierter QR-Code

class="content__image-caption">ZXing Dekodierungsergebnis

Preis- und Lizenzierungsbedingungen

Die ZXing.NET-Bibliothek ist eine kostenlose Open-Source-Bibliothek, die es Ihnen ermöglicht, Barcode-Leseanwendungen zu erstellen, lizenziert unter der Apache License 2.0, die kostenfreie kommerzielle Nutzung mit korrekter Attribution erlaubt.

Eine Entwicklerlizenz für IronBarcode wird kostenlos angeboten. IronBarcode hat ein einzigartiges Preismodell: Das Lite-Paket beginnt bei $liteLicense ohne zusätzliche Kosten. SaaS- und OEM-Artikel können ebenfalls erneut vertrieben werden. Jede Lizenz beinhaltet eine unbefristete Lizenz, Gültigkeit für Entwicklung/Test/Produktion, eine 30-tägige Geld-zurück-Garantie und ein Jahr Software-Support und Upgrades (einmaliger Kauf). Besuchen Sie diese Seite, um IronBarcodes vollständige Preis- und Lizenzinformationen einzusehen.

Warum IronBarcode wählen?

IronBarcode enthält eine einfach zu bedienende API für Entwickler, um Barcodes in .NET zu lesen und zu schreiben, und optimiert Genauigkeit und eine niedrige Fehlerquote in realen Anwendungsfällen.

Die BarcodeWriter-Klasse wird zum Beispiel Checksummen auf UPCA- und UPCE-Barcodes validieren und korrigieren. Es wird auch Zahlen mit Nullen auffüllen, die zu kurz sind, um in ein bestimmtes numerisches Format eingegeben zu werden. Wenn Ihre Daten mit dem angegebenen Datenformat nicht kompatibel sind, wird IronBarcode den Entwickler auf ein geeigneteres Barcode-Format hinweisen, das sie verwenden können.

IronBarcode übertrifft beim Lesen von Barcodes, wenn der Barcode gescannt wurde oder aus einem fotografischen Bild gelesen wurde, das heißt, wenn das Bild nicht perfekt grafisch ist und kein maschinell generierter Screenshot ist.

Wie unterscheidet sich IronBarcode von ZXing.NET?

IronBarcode ist aus dem ZXing.NET (Zebra Crossing) Kern aufgebaut, mit verbesserter Verarbeitungsfähigkeit. Es kommt mit einer einfach zu bedienenden API und einer niedrigen Fehlerquote im Vergleich zur ZXing.NET-Kernbibliothek. Nicht nur das, sondern IronBarcode unterstützt auch eine größere Auswahl an Barcode-Formaten als die übliche ZXing.NET-Bibliothek.

IronBarcode ist eine verbesserte Version von ZXing.NET, die dem Benutzer die Möglichkeit bietet, das gleiche Paket auf mehreren Plattformen kommerziell zu verwenden. Es bietet auch umfassenden technischen Support, der jederzeit bereit ist zu helfen, wo immer nötig.

IronBarcode enthält automatische Drehung, Perspektivkorrektur und digitale Rauschkorrektur und kann den in einem Bild kodierten Barcode-Typ erkennen.

Abschluss

Zusammenfassend lässt sich sagen, dass IronBarcode eine vielseitige .NET-Softwarebibliothek und ein C#-QR-Code-Generator ist, um eine breite Palette von Barcode-Formaten zu lesen, unabhängig davon, ob es sich um Screenshots, Fotografien, Scans oder andere unvollkommene reale Bilder handelt.

IronBarcode ist eine der effektivsten Bibliotheken zum Erstellen und Identifizieren von Barcodes. In Bezug auf das Erstellen und Identifizieren von Barcodes ist es auch eine der schnellsten Bibliotheken. Verschiedene Betriebssysteme sind mit der Bibliothek kompatibel. Es ist einfach zu entwerfen und unterstützt eine breite Palette von Barcode-Formaten. Darüber hinaus werden verschiedene Symbole, Formate und Zeichen unterstützt.

ZXing.NET-Barcode ist eine leistungsstarke Bibliothek, die Barcodes in verschiedenen Bildformaten generiert und erkennt. Wir können Bilder in verschiedenen Formaten lesen und erstellen. ZXing.NET ermöglicht es Ihnen auch, das Erscheinungsbild eines Barcodes zu ändern, seine Höhe, Breite, Barcode-Text usw. anzupassen.

Im Vergleich zu ZXing.NET bieten IronBarcode-Pakete zuverlässige Lizenzierung und Unterstützung. IronBarcode kostet $liteLicense. Obwohl ZXing kostenlos und Open Source ist, bietet IronBarcode umfassenden kommerziellen Support und professionelle Wartung. Zusätzlich zur Flexibilität im Vergleich zu ZXing.NET bietet IronBarcode-Lösung auch mehr Funktionalität. Daher ist offensichtlich, dass IronBarcode einen starken Vorteil gegenüber ZXing.NET hat.

Beim Vergleich der Verarbeitungszeiten für das Erkennen und Generieren von Barcodes übertrifft IronBarcode ZXing.NET. IronBarcode hat auch mehrere Eigenschaften, die es uns ermöglichen, Barcodes aus verschiedenen Bildformaten und PDF-Dokumenten zu lesen. Es ermöglicht uns auch, Bilder in den Barcode oder QR-Code einzufügen, was in keiner anderen Bibliothek möglich ist.

IronBarcode ist kostenlos für die frühen Entwicklungsstadien. Sie können eine kostenlose Testversion für den produktionsstufen- oder kommerziellen Gebrauch erwerben. Je nach den Anforderungen des Entwicklers bietet IronBarcode drei Preisklassen. Sie können die Lösung auswählen, die Ihre Anforderungen am besten erfüllt. Sie können jetzt eine Suite von fünf Iron Software-Produkten zum Preis von zwei Iron Software-Artikeln erhalten. Besuchen Sie diese Website für weitere Informationen.

Hinweis:ZXing.NET ist eine eingetragene Marke seines jeweiligen Inhabers. Diese Website ist nicht mit ZXing.NET verbunden, wird nicht von ZXing.NET unterstützt oder gesponsert. Alle Produktnamen, Logos und Marken sind Eigentum ihrer jeweiligen Eigentümer. Vergleiche dienen nur zu Informationszwecken und spiegeln öffentlich zugängliche Informationen zum Zeitpunkt des Schreibens wider.

Häufig gestellte Fragen

Wie kann ich einen QR-Code in C# generieren?

Sie können einen QR-Code in C# mit IronBarcode generieren, indem Sie die `BarcodeWriter`-Klasse verwenden. Definieren Sie einfach den Inhalt des QR-Codes, passen Sie Optionen wie Farbe und Größe an und rufen Sie die `Write`-Methode auf, um den QR-Code zu generieren.

Was macht IronBarcode robuster als ZXing.NET?

IronBarcode bietet erweiterte Fähigkeiten wie die Unterstützung einer breiteren Palette von Barcode-Formaten, fortschrittliche Bildverarbeitungsfunktionen wie Rotations- und Perspektivkorrektur sowie die Möglichkeit, dekorierte QR-Codes mit Logos und Farben zu erstellen. Es ist auch plattformübergreifend kompatibel und bietet kommerziellen Support.

Kann ich Barcodes aus Bildern mit Unvollkommenheiten mit IronBarcode lesen?

Ja, IronBarcode kann Barcodes aus Bildern mit Unvollkommenheiten lesen, indem es Funktionen wie Rotationskorrektur, Perspektivkorrektur und digitale Rauschreduzierung verwendet, was es effektiv für gescannte oder fotografierte Bilder macht.

Was sind die Schritte, um einen Barcode in C# zu lesen?

Um einen Barcode in C# zu lesen, verwenden Sie IronBarcode's `BarcodeReader`-Klasse. Laden Sie das Bild, das den Barcode enthält, mit der Methode `BarcodeReader.QuicklyReadOneBarcode`, die den Barcode-Inhalt dekodiert und zurückgibt, wenn er erkannt wird.

Wie geht IronBarcode mit plattformübergreifender Kompatibilität um?

IronBarcode unterstützt plattformübergreifende Kompatibilität für Windows, macOS, Linux und Azure, sodass Sie Barcode-Generierungs- und Lese-Funktionalitäten in verschiedene .NET-Anwendungen ohne Drittanbieter-Abhängigkeiten integrieren können.

Welche Optionen gibt es zur Anpassung von QR-Codes mit IronBarcode?

IronBarcode ermöglicht die Anpassung von QR-Codes durch die Anpassung von Farben, das Hinzufügen von Logos zur Markenbildung und das Konfigurieren von Fehlerkorrekturstufen, um Größe und Lesbarkeit auszugleichen, und bietet so Flexibilität für verschiedene ästhetische und funktionale Anforderungen.

Gibt es eine Lizenzgebühr für die Verwendung von IronBarcode in kommerziellen Anwendungen?

IronBarcode bietet verschiedene Lizenzierungsoptionen, einschließlich einer dauerhaften Lizenz, die für kommerzielle Anwendungen geeignet ist. Dies steht im Gegensatz zu ZXing.NET, das kostenlos ist, aber Einschränkungen für die kommerzielle Nutzung hat.

Was sind häufige Fehlerszenarien bei der Verwendung von Barcode-Bibliotheken?

Häufige Probleme können eine falsche Barcode-Erkennung aufgrund schlechter Bildqualität, nicht unterstützte Barcode-Formate oder Konfigurationsfehler umfassen. IronBarcode's fortschrittliche Bildverarbeitung kann einige Erkennungsprobleme mindern.

Warum sollte jemand IronBarcode gegenüber ZXing.NET für die Barcode-Verarbeitung wählen?

IronBarcode bietet eine robustere API, besseres Fehlerhandling, umfangreiche Barcode-Formatunterstützung und Funktionen zur Erzeugung visuell angepasster QR-Codes, alles mit dem zusätzlichen Vorteil kommerzieller Lizenzierung und professionellen Supports.

Wie kann man IronBarcode in einem .NET-Projekt installieren?

Sie können IronBarcode in einem .NET-Projekt über den NuGet Package Manager in Visual Studio installieren, indem Sie nach 'IronBarcode' suchen und es Ihrem Projekt hinzufügen, was eine einfache Integration und Aktualisierungen gewährleistet.

Jordi Bardia
Software Ingenieur
Jordi ist am besten in Python, C# und C++ versiert. Wenn er nicht bei Iron Software seine Fähigkeiten einsetzt, programmiert er Spiele. Mit Verantwortung für Produkttests, Produktentwicklung und -forschung trägt Jordi mit immensem Wert zur kontinuierlichen Produktverbesserung bei. Die abwechslungsreiche Erfahrung hält ihn gefordert und engagiert, ...
Weiterlesen