C# 및 VB.NET 애플리케이션의 바코드 및 QR 코드
C#과 기타 모든 .NET 언어로 바코드를 읽고 쓰는 것은 IronBarcode 소프트웨어 라이브러리를 사용하면 간단한 과정입니다.
IronBarcode 설치하기
이 여정의 첫 번째 단계는 IronBarcode를 설치하는 것이며, 이는 NuGet에서 다운로드하거나 DLL을 다운로드하여 수행할 수 있습니다.
IronBarcode NuGet 패키지를 설치하려면 Visual Studio용 NuGet 패키지 관리자를 사용할 수 있습니다:
대안으로, .NET CLI를 사용하여 설치할 수도 있습니다:
바코드 또는 QR 코드 읽기
IronBarcode를 사용하면 바코드를 읽는 데 단 한 줄의 코드만 필요합니다.
using IronBarCode;
BarcodeResults results = BarcodeReader.Read("QuickStart.jpg");
if (results != null)
{
foreach (BarcodeResult result in results)
{
Console.WriteLine(result.Text);
}
}Imports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("QuickStart.jpg")
If results IsNot Nothing Then
For Each result As BarcodeResult In results
Console.WriteLine(result.Text)
Next result
End IfImports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("QuickStart.jpg")
If results IsNot Nothing Then
For Each result As BarcodeResult In results
Console.WriteLine(result.Text)
Next result
End If이 한 줄의 코드로, 입력 문서에서 모든 유형의 바코드를 감지하고 스캔할 수 있는 뛰어난 성능을 발휘할 수 있습니다. 필요한 모든 것이 한 단계로 가능합니다! 이 메서드는 JPEG, PNG, BMP와 같은 다양한 이미지 형식뿐만 아니라 PDF 및 GIF 및 TIFF와 같은 다중 프레임 형식도 지원합니다. 향상된 성능을 위해 맞춤형 구성 옵션을 사용할 수 있습니다.
읽기 속도를 개선하기 위해 성능을 향상시키기 위한 Speed 설정이 구성된 BarcodeReaderOptions 객체를 생성할 수 있습니다. 기본값은 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);
}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);
}Imports IronBarCode
Imports System
Imports System.Linq
Dim myOptionsExample As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
.CropArea = New System.Drawing.Rectangle(100, 200, 300, 400)
}
Dim result As BarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample)
If result IsNot Nothing Then
Console.WriteLine(result.First().Text)
End IfImports IronBarCode
Imports System
Imports System.Linq
Dim myOptionsExample As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
.CropArea = New System.Drawing.Rectangle(100, 200, 300, 400)
}
Dim result As BarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample)
If result IsNot Nothing Then
Console.WriteLine(result.First().Text)
End If읽기 프로세스를 최적화하기 위해 OnlyBasicScan로 ScanMode를 설정할 수도 있습니다.
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 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);
}Imports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.png")
' Loop through the results
For Each result As BarcodeResult In results
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next resultImports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.png")
' Loop through the results
For Each result As BarcodeResult In results
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next result기타 구성에는 스캔할 바코드 형식을 지정하여 불필요한 스캔을 줄여 처리 속도를 높이는 방법이 포함됩니다.
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
});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
});Imports IronBarCode
Private pagedResults As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.pdf")
' Loop through the results
For Each result As BarcodeResult In pagedResults
Dim pageNumber As Integer = result.PageNumber
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next result
' or from a multi-page TIFF scan with image correction:
Dim multiFrameResults As BarcodeResults = BarcodeReader.Read(inputImage:= "Multiframe.tiff", New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Detailed,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code128,
.Multithreaded = False,
.RemoveFalsePositive = False,
.ImageFilters = Nothing
})Imports IronBarCode
Private pagedResults As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.pdf")
' Loop through the results
For Each result As BarcodeResult In pagedResults
Dim pageNumber As Integer = result.PageNumber
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next result
' or from a multi-page TIFF scan with image correction:
Dim multiFrameResults As BarcodeResults = BarcodeReader.Read(inputImage:= "Multiframe.tiff", New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Detailed,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code128,
.Multithreaded = False,
.RemoveFalsePositive = False,
.ImageFilters = Nothing
})바코드 쓰기
IronBarcode를 사용하여 바코드를 작성하려면 BarcodeWriter 클래스를 사용합니다.
using IronBarCode;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.SaveAsImage("myBarcode.png");using IronBarCode;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.SaveAsImage("myBarcode.png");Imports IronBarCode
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)
myBarcode.SaveAsImage("myBarcode.png")Imports IronBarCode
Private myBarcode As GeneratedBarcode = 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");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");Imports IronBarCode
Private myBarcode As GeneratedBarcode = 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")Imports IronBarCode
Private myBarcode As GeneratedBarcode = 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");using IronBarCode;
QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf");Imports IronBarCode
QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf")Imports 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");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");Imports IronBarCode
Imports IronSoftware.Drawing
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo)
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf")Imports IronBarCode
Imports IronSoftware.Drawing
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo)
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf")지원되는 바코드 형식
IronBarcode는 읽기와 쓰기에 대해 널리 사용되는 여러 바코드 형식을 지원합니다:
- QR, Micro QR, Rectangular Micro QR (rMQR) 코드.
- Aztec, Data Matrix, MaxiCode, PDF417과 같은 기타 2차원 바코드.
- Databar와 같은 스택형 선형 바코드.
- UPC-A, UPC-E, EAN-8, EAN-13, Codabar, ITF, MSI, Plessey와 같은 일반적인 1차원 바코드 형식.
왜 IronBarcode를 선택해야 하는가?
IronBarcode는 .NET을 위한 바코드 읽기 및 쓰기에 대해 친숙하고 사용하기 쉬운 API를 제공하며, 실제 사용 시 정확성, 정밀도 및 속도를 최적화합니다.
예를 들어, BarcodeWriter 클래스는 UPCA 및 UPCE 바코드에서 '검사합'을 자동으로 검증 및 수정하고 숫자 형식 제약을 처리합니다. IronBarcode는 개발자가 데이터에 가장 적합한 바코드 형식을 선택하는 데 도움을 줍니다.
라이브러리는 자동 회전 및 이미지 노이즈 제거와 같은 이미지 전처리 기술을 통해 바코드 감지 성공률을 극대화할 수 있습니다.
앞으로 나아가기
IronBarcode를 최대한 활용하려면 이 문서 섹션의 튜토리얼을 읽고 GitHub에서 저희를 방문하시기를 권장합니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.