Barcodes & QRs in C# & VB.NET Applications
C# 및 기타 모든 .NET 언어에서 BarCode를 읽고 쓰는 작업은 당사의 IronBarcode 라이브러리를 사용하면 간편하게 수행할 수 있습니다.
IronBarcode 설치
이 여정의 첫 단계는 IronBarcode를 설치하는 것이며, NuGet에서 다운로드하거나 DLL 파일을 직접 다운로드하여 설치할 수 있습니다.
IronBarcode NuGet 패키지를 설치하려면 Visual Studio용 NuGet 패키지 관리자를 사용할 수 있습니다:
Install-Package BarCode
또는 .NET CLI를 사용하여 설치할 수도 있습니다:
dotnet add package IronBarCode
BarCode 또는 QR 코드 읽기
IronBarcode를 사용하면 단 한 줄의 코드만으로 BARCODE를 읽을 수 있습니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-1.cs
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 If
이 한 줄의 코드만으로 입력 문서에서 모든 유형의 BarCode를 뛰어난 성능으로 감지하고 스캔할 수 있습니다. 필요한 모든 작업이 한 번에 해결됩니다! 이 메서드는 JPEG, PNG, BMP와 같은 다양한 이미지 형식뿐만 아니라 PDF 및 GIF, TIFF와 같은 다중 프레임 형식도 지원합니다. 성능 향상을 위해 사용자 정의 가능한 구성 옵션을 제공합니다.
읽기 속도를 높이기 위해, 더 나은 성능을 위해 Speed 설정이 구성된 BarcodeReaderOptions 객체를 생성할 수 있습니다. 기본값은 Balanced이지만, Faster 옵션을 사용하여 특정 검사를 건너뛸 수 있습니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-2.cs
using IronBarCode;
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
Private myOptionsExample As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
.CropArea = New System.Drawing.Rectangle(100, 200, 300, 400)
}
Private result As BarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample)
If result IsNot Nothing Then
Console.WriteLine(result.First().Text)
End If
또한 ScanMode을 OnlyBasicScan로 설정하여 가독성을 높일 수 있습니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-3.cs
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 result
기타 구성 옵션으로는 스캔할 BarCode 형식을 지정하는 기능이 있으며, 이를 통해 불필요한 스캔을 줄여 처리 속도를 높일 수 있습니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-4.cs
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
})
BarCode 작성
IronBarcode를 사용하여 BARCODE를 작성하려면 BarcodeWriter 클래스를 사용합니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-5.cs
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")
BarCode 스타일링
IronBarcode는 BarCode의 시각적 표현을 조작할 수 있는 여러 가지 옵션을 제공합니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-7.cs
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")
BarCode를 HTML로 내보내기
IronBarcode는 BARCODE를 HTML 문서로 내보내거나 HTML 콘텐츠의 일부로 포함시킬 수 있습니다.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-8.cs
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")
QR 코드 생성
QR 코드의 경우, 오류 정정 등 QR 코드 특유의 기능을 위한 추가 구성을 제공하는 QRCodeWriter 클래스를 사용하십시오.
:path=/static-assets/barcode/content-code-examples/get-started/get-started-9.cs
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")
지원되는 바코드 형식
IronBarcode는 읽기 및 쓰기 모두에 대해 널리 사용되는 다양한 BarCode 형식을 지원합니다:
- QR, Micro QR 및 직사각형 Micro QR(rMQR) 코드.
- Aztec, Data Matrix, MaxiCode, PDF417과 같은 기타 2차원 BARCODE.
- Databar와 같은 적층형 선형 BARCODE.
- UPC-A, UPC-E, EAN-8, EAN-13, Codabar, ITF, MSI 및 Plessey와 같은 기존의 1차원 BARCODE 형식.
왜 IronBarcode를 선택해야 할까요?
IronBarcode for .NET은 개발자가 .NET 환경에서 바코드를 읽고 쓸 수 있도록 친숙하고 사용하기 쉬운 API를 제공하며, 실제 사용 사례에서 정확성, 정밀도 및 속도를 최적화합니다.
예를 들어, BarcodeWriter 클래스는 UPCA 및 UPCE BARCODE의 '체크섬'을 자동으로 검증하고 수정하며, 숫자 형식 제약 조건을 처리합니다. IronBarcode는 개발자가 자신의 데이터에 가장 적합한 BarCode 형식을 선택할 수 있도록 지원합니다.
이 라이브러리는 자동 회전 및 이미지 노이즈 제거와 같은 이미지 전처리 기술을 통해 BarCode 인식 성공률을 극대화하는 등 강력한 성능을 자랑합니다.
향후 계획
IronBarcode를 최대한 활용하시려면, 이 문서 섹션에 포함된 튜토리얼을 읽어보시고 GitHub 페이지를 방문해 보시기 바랍니다.

