
C# 윈도우 앱에서 바코드 스캐너를 사용하는 방법
이 튜토리얼에서는 IronBarcode 라이브러리를 예로 들어 C# 콘솔 애플리케이션 및 .NET 윈도우 폼 애플리케이션에서 QR 코드 및 바코드를 스캔하는 방법을 보여줄 것입니다.
IronBarcode 라이브러리를 사용하면 여러 바코드를 동시에 스캔하고 읽을 수 있으며, 불완전한 이미지를 성공적으로 스캔할 수도 있습니다. 먼저 바코드 스캐너가 무엇인지 명확히 하자.
바코드 스캐너란 무엇인가?
바코드는 다양한 너비의 평행한 검은 선과 흰색 공간으로 이루어진 정사각형 또는 직사각형 이미지입니다. 바코드 스캐너 또는 바코드 리더기는 인쇄된 바코드를 읽고, 바코드에 포함된 데이터를 디코딩하며, 데이터를 컴퓨터에 전송할 수 있는 장치입니다.
다음 단계에서는 IronBarcode 라이브러리를 사용하여 바코드 스캐너를 만드는 방법을 소개합니다.
C#에서 바코드를 읽는 방법
- Microsoft Visual Studio에서 .NET Windows Forms 애플리케이션 프로젝트 생성
- 바코드 라이브러리 설치
- 모든 바코드 또는 QR 코드 읽기
- 한 번의 스캔으로 여러 바코드 또는 QR 코드 읽기
- IronBarcode가 불완전한 스캔 및 사진에서 읽을 수 있도록 허용
1. Microsoft Visual Studio에서 Windows Forms 애플리케이션 생성
Visual Studio 열기 > Create New Project 클릭 > Windows Forms Application Template 선택 > Next 누르기 > 프로젝트 이름 입력 > Next 누르기 > 대상 .NET Framework 선택 > Create 버튼 클릭.
프로젝트를 생성한 후, Visual Studio 도구 상자에서 다음과 같이 폼을 설계하세요: PictureBox, Label, TextBox, 그리고 Button 컨트롤.
바코드 스캐너
2. C#에서 바코드 .NET 라이브러리 설치
바코드 라이브러리는 다음 세 가지 방법 중 하나를 사용하여 설치할 수 있습니다.
1. 패키지 관리자 콘솔
패키지 관리자 콘솔에 다음 명령어를 입력하세요. 패키지를 다운로드하고 설치할 것입니다.
2. NuGet 패키지 관리자 솔루션
NuGet 패키지 솔루션을 사용하여 바코드 라이브러리를 설치할 수도 있습니다. 다음 단계를 따르세요.
도구 > NuGet 패키지 관리자 > 솔루션용 NuGet 패키지 관리를 클릭하세요.
이렇게 하면 NuGet 패키지 관리자가 열립니다. Browse를 클릭하고 Barcode를 검색한 다음 클래스 라이브러리를 설치하세요.
3. 링크에서 다운로드
IronBarCode.Dll을 다운로드하여 프로젝트 참조로 추가할 수 있습니다.
다운로드 후, 바코드 리더 프로젝트에 다음의 참조를 추가하세요.
using IronBarCode;Imports IronBarCode3. 바코드 또는 QR 코드 읽기
.NET에서 IronBarcode 라이브러리를 사용하여 바코드 또는 QR 코드를 읽는 것은 매우 쉽습니다. .NET 바코드 리더.
바코드 스캐너
프로젝트에서 읽고자 하는 이미지를 검색하세요. 그것은 PictureBox에서 열립니다; 이제 '코드 스캔'을 클릭하세요. 텍스트는 텍스트 상자에 나타납니다.
'검색' 버튼을 열어 이미지를 열기 위한 코드는 다음과 같습니다:
// Open file dialog
OpenFileDialog open = new OpenFileDialog();
// Image filters
open.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp";
if (open.ShowDialog() == DialogResult.OK) {
// Display image in PictureBox
pictureBox1.Image = new Bitmap(open.FileName);
// Store image file path in class data member. Initialize it as string ImageFileName;
ImageFileName = open.FileName;
}' Open file dialog
Dim open As New OpenFileDialog()
' Image filters
open.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp"
If open.ShowDialog() = DialogResult.OK Then
' Display image in PictureBox
pictureBox1.Image = New Bitmap(open.FileName)
' Store image file path in class data member. Initialize it as string ImageFileName;
ImageFileName = open.FileName
End If'코드 스캔' 버튼의 코드:
// Read the barcode from the image file path
BarcodeResult Result = BarcodeReader.Read(ImageFileName);
// Display the decoded text in TextBox
textBox1.Text = Result.Text;' Read the barcode from the image file path
Dim Result As BarcodeResult = BarcodeReader.Read(ImageFileName)
' Display the decoded text in TextBox
textBox1.Text = Result.Text바코드 스캐너는 텍스트 상자에 바코드 데이터를 다음과 같이 표시합니다:
C#으로 스캔할 바코드 이미지
QR 코드 스캐너
이 섹션에서는 IronBarcode 라이브러리가 비스듬한 QR 코드를 포함한 실제 상황을 효과적으로 처리합니다. 비록 비스듬한 각도의 QR 코드가 Read 메서드에 의해 처리되고 읽힐 수 있지만, 해결하는 데 더 많은 시간이 걸릴 수 있습니다. IronBarcode 라이브러리는 이러한 이미지 입력을 처리하기 위해 추가 매개변수로 BarcodeReaderOptions을(를) 사용하는 맞춤화된 방법을 제공합니다. 코드는 다음과 같습니다.
// Define a collection of image filters to apply
var filtersToApply = new ImageFilterCollection() {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter()
};
// Configure barcode reader options with specified filters
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() {
ImageFilters = filtersToApply,
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
};
// Read the barcode/QR code with custom options and display result
BarcodeResult Result = BarcodeReader.Read(ImageFileName, myOptionsExample);
textBox1.Text = Result.Text;' Define a collection of image filters to apply
Dim filtersToApply = New ImageFilterCollection() From {
New SharpenFilter(),
New InvertFilter(),
New ContrastFilter(),
New BrightnessFilter(),
New AdaptiveThresholdFilter(),
New BinaryThresholdFilter()
}
' Configure barcode reader options with specified filters
Dim myOptionsExample As New BarcodeReaderOptions() With {
.ImageFilters = filtersToApply,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128
}
' Read the barcode/QR code with custom options and display result
Dim Result As BarcodeResult = BarcodeReader.Read(ImageFileName, myOptionsExample)
textBox1.Text = Result.Text비스듬한 QR 코드 이미지를 연 후 출력은 다음과 같습니다:
비스듬한 QR 코드 이미지
단일 스캔에서 여러 개의 바코드를 읽기
PDF 문서
바코드 이미지는 PDF 파일에서 스캔할 수 있으며, 각 결과는 원하는 대로 적절히 표시할 수 있습니다. 다음 샘플 코드는 PDF 파일에서 여러 바코드를 읽을 수 있게 합니다.
// Scan for multiple barcodes within a PDF document
BarcodeResult[] PDFResults = BarcodeReader.ReadPdf("MultipleBarcodes.pdf");
// Work with the results found
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);
}' Scan for multiple barcodes within a PDF document
Dim PDFResults() As BarcodeResult = BarcodeReader.ReadPdf("MultipleBarcodes.pdf")
' Work with the results found
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 PageResultPDF 파일에 포함된 바코드 및 QR 코드:
C# - PDF에서 바코드를 읽는 결과
불완전한 이미지에서 바코드 읽기
실제 사용 사례에서는 바코드가 이미지, 스캔본, 썸네일 또는 사진에서 불완전하게 발견되며, 디지털 노이즈를 포함하거나 비스듬할 수 있습니다. 이 섹션은 썸네일에서 바코드 데이터를 읽는 방법을 보여줍니다.
썸네일
IronBarcode 라이브러리는 C# 바코드 생성기를 사용하여 손상된 바코드 썸네일조차도 읽을 수 있습니다.
자동 바코드 썸네일 크기 보정. IronBarcode로 읽을 수 있는 파일 C#
그것은 실제 바코드를 합리적으로 표현하기에 너무 작은 바코드 이미지를 자동으로 감지하고, 그 후 썸네일링과 관련된 모든 디지털 노이즈를 업스케일 및 정리하여 다시 읽을 수 있도록 합니다.
// Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.Read("ThumbnailOfBarcode.gif");' Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
Dim SmallResult As BarcodeResult = BarcodeReader.Read("ThumbnailOfBarcode.gif")요약
IronBarcode는 다양한 바코드 이미지 형식을 스캔하고 읽을 수 있는 다용도의 .NET 소프트웨어 라이브러리이며, 이는 바코드가 완벽한 스크린 캡처인지 아니면 실제 사진, 스캔 또는 다른 불완전한 실제 이미지인지에 상관없이 가능합니다. 또한, IronBarcode는 크롭 영역이나 멀티스레딩과 ML 모델의 정확성과 같은 바코드 읽기 속도를 향상시키기 위한 다양한 사용자 정의 옵션을 제공합니다. 공식 문서 페이지를 방문하여 IronBarcode에 대한 더 많은 정보를 확인하세요.
현재, 완전한 Iron Suite를 구매하면 두 개의 가격에 5개의 라이브러리를 얻을 수 있습니다.

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.
관련 기사


