C#에서 QR 코드 유형 읽는 방법
런타임에서 스캔된 QR 코드의 형식을 식별하세요. QrResult.QrType를 읽어 기호학을 감지하고 다양한 입력 소스에 대한 유형 인식 처리 로직을 구축합니다.
응용 프로그램이 여러 소스에서 QR 코드를 수락할 때, 형식은 항상 예측할 수 없습니다. 물류 플랫폼은 배송 라벨에서 표준 QR 코드를 수신할 수 있으며, 제품 태그에서 컴팩트 마이크로 QR 코드를 받을 수 있습니다. 문서 처리 시스템은 PDF에 내장된 코드를 스캔할 수 있으며, 물리적인 미디어에 인쇄된 코드도 스캔할 수 있습니다. QrResult.QrType를 읽으면 애플리케이션이 어떤 형식이 감지되었는지 알 수 있어 입력을 검증하거나 데이터를 올바른 핸들러로 라우팅하거나 검토를 위해 지원되지 않는 형식을 기록할 수 있습니다.
이 가이드는 IronQR 라이브러리를 사용하여 스캔 결과에서 QR 코드 형식을 검색하는 방법을 설명합니다. 아직 QR 코드를 스캔하지 않은 개발자는 먼저 이미지에서 QR 코드 읽기 가이드를 참조하십시오.
빠른 시작: QR 코드 유형 읽기이미지를 로드한 후 QrReader로 스캔하고 감지된 형식에 액세스합니다.
-
1IronQR를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
var input = new QrImageInput(AnyBitmap.FromFile("qr-code.png")); var results = new QrReader().Read(input); Console.WriteLine(results.First().QrType);Dim input = New QrImageInput(AnyBitmap.FromFile("qr-code.png")) Dim results = (New QrReader()).Read(input) Console.WriteLine(results.First().QrType)Dim input = New QrImageInput(AnyBitmap.FromFile("qr-code.png")) Dim results = (New QrReader()).Read(input) Console.WriteLine(results.First().QrType) -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronQR 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- QR 코드 유형을 읽기 위한 IronQR C# 라이브러리를 다운로드하세요
- 이미지를 로드하고
QrImageInput에 그것을 감싸세요 QrReader인스턴스를 생성하고 입력과 함께Read호출QrResult.QrType를 통해 감지된 형식에 접근하세요.QrEncoding에 대한switch를 사용하여 형식별로 처리 라우팅
QR 코드 유형을 읽는 방법은?
QR 코드의 유형을 읽으려면 이미지를 QrImageInput에 로드하고 QrReader.Read()에 전달하며 반환된 QrResult에서 QrType에 액세스합니다. 이 속성은 감지된 기호학을 식별하는 QrEncoding 열거형 값을 반환합니다.
입력
아래 QR 코드는 https://ironsoftware.com을(를) 인코딩하며 그 유형을 추출하기 위해 스캔됩니다.

using IronQr;
using System.Drawing;
using System.Linq;
// Import an image containing a QR code
var inputImage = Image.FromFile("sample.jpg");
// Load the asset into a QrImageInput object
QrImageInput imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
QrReader reader = new QrReader();
// Read the input and get all embedded QR codes
IEnumerable<QrResult> results = reader.Read(imageInput);
// Display the type of the first QR code found
Console.WriteLine($"The QR type is {results.First().QrType}");using IronQr;
using System.Drawing;
using System.Linq;
// Import an image containing a QR code
var inputImage = Image.FromFile("sample.jpg");
// Load the asset into a QrImageInput object
QrImageInput imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
QrReader reader = new QrReader();
// Read the input and get all embedded QR codes
IEnumerable<QrResult> results = reader.Read(imageInput);
// Display the type of the first QR code found
Console.WriteLine($"The QR type is {results.First().QrType}");Imports IronQr
Imports System.Drawing
Imports System.Linq
' Import an image containing a QR code
Dim inputImage As Image = Image.FromFile("sample.jpg")
' Load the asset into a QrImageInput object
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read the input and get all embedded QR codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Display the type of the first QR code found
Console.WriteLine($"The QR type is {results.First().QrType}")Imports IronQr
Imports System.Drawing
Imports System.Linq
' Import an image containing a QR code
Dim inputImage As Image = Image.FromFile("sample.jpg")
' Load the asset into a QrImageInput object
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read the input and get all embedded QR codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Display the type of the first QR code found
Console.WriteLine($"The QR type is {results.First().QrType}")QrType는 QrEncoding 열거형 값을 반환합니다. 예를 들어 QrEncoding.QRCode, QrEncoding.MicroQRCode 또는 QrEncoding.RMQRCode가 있습니다. 이로 인해 구문 분석이나 문자열 비교 없이 직접 switch 문에서 안전하게 사용할 수 있습니다.
산출

QR 코드 형식을 기준으로 처리 라우팅하는 방법은?
애플리케이션이 여러 소스에서 QR 코드를 받으면 모든 입력이 동일한 형식이 아닐 수 있습니다. 각 감지된 코드를 QrEncoding 값에 따라 올바른 핸들러로 라우트하기 위해 QrResult.QrType에서 switch를 사용합니다. 형식별 논리를 분리하여 새로운 형식 분기를 추가하는 것이 간단합니다.
아래의 동일한 입력 QR 코드를 사용하여:
using IronQr;
using IronQr.Enum;
using System.Drawing;
// Import an image containing QR codes
var inputImage = Image.FromFile("sample.jpg");
// Load the asset into a QrImageInput object
QrImageInput imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
QrReader reader = new QrReader();
// Read all embedded QR codes from the image
IEnumerable<QrResult> results = reader.Read(imageInput);
// Route processing based on the detected QR code format
foreach (QrResult result in results)
{
switch (result.QrType)
{
case QrEncoding.QRCode:
Console.WriteLine($"Standard QR Code: {result.Value}");
break;
case QrEncoding.MicroQRCode:
Console.WriteLine($"Micro QR Code: {result.Value}");
break;
case QrEncoding.RMQRCode:
Console.WriteLine($"RMQR Code: {result.Value}");
break;
default:
Console.WriteLine($"Other format ({result.QrType}): {result.Value}");
break;
}
}using IronQr;
using IronQr.Enum;
using System.Drawing;
// Import an image containing QR codes
var inputImage = Image.FromFile("sample.jpg");
// Load the asset into a QrImageInput object
QrImageInput imageInput = new QrImageInput(inputImage);
// Create a QR Reader object
QrReader reader = new QrReader();
// Read all embedded QR codes from the image
IEnumerable<QrResult> results = reader.Read(imageInput);
// Route processing based on the detected QR code format
foreach (QrResult result in results)
{
switch (result.QrType)
{
case QrEncoding.QRCode:
Console.WriteLine($"Standard QR Code: {result.Value}");
break;
case QrEncoding.MicroQRCode:
Console.WriteLine($"Micro QR Code: {result.Value}");
break;
case QrEncoding.RMQRCode:
Console.WriteLine($"RMQR Code: {result.Value}");
break;
default:
Console.WriteLine($"Other format ({result.QrType}): {result.Value}");
break;
}
}Imports IronQr
Imports IronQr.Enum
Imports System.Drawing
' Import an image containing QR codes
Dim inputImage As Image = Image.FromFile("sample.jpg")
' Load the asset into a QrImageInput object
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read all embedded QR codes from the image
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Route processing based on the detected QR code format
For Each result As QrResult In results
Select Case result.QrType
Case QrEncoding.QRCode
Console.WriteLine($"Standard QR Code: {result.Value}")
Case QrEncoding.MicroQRCode
Console.WriteLine($"Micro QR Code: {result.Value}")
Case QrEncoding.RMQRCode
Console.WriteLine($"RMQR Code: {result.Value}")
Case Else
Console.WriteLine($"Other format ({result.QrType}): {result.Value}")
End Select
NextImports IronQr
Imports IronQr.Enum
Imports System.Drawing
' Import an image containing QR codes
Dim inputImage As Image = Image.FromFile("sample.jpg")
' Load the asset into a QrImageInput object
Dim imageInput As New QrImageInput(inputImage)
' Create a QR Reader object
Dim reader As New QrReader()
' Read all embedded QR codes from the image
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Route processing based on the detected QR code format
For Each result As QrResult In results
Select Case result.QrType
Case QrEncoding.QRCode
Console.WriteLine($"Standard QR Code: {result.Value}")
Case QrEncoding.MicroQRCode
Console.WriteLine($"Micro QR Code: {result.Value}")
Case QrEncoding.RMQRCode
Console.WriteLine($"RMQR Code: {result.Value}")
Case Else
Console.WriteLine($"Other format ({result.QrType}): {result.Value}")
End Select
Next각 case는 특정 QrEncoding 값을 목표로 합니다. QrType 분기에서는 명시적으로 처리되지 않은 형식을 포착하여 예기치 않은 입력으로 인해 루프가 조용히 실패하지 않도록 합니다. 애플리케이션이 추가 형식을 지원하도록 더 많은 경우를 추가하세요.
산출

QrResult.QrType는 무엇을 반환합니까?
QrResult.QrType은(는) 스캐너에 의해 감지된 심볼로지를 식별하는 모든 QrResult에서 enum가 사용된 QrEncoding 속성입니다. 이는 QrReader.Read() 중에 자동으로 채워지며 추가 설정이 필요하지 않습니다. 직접 switch에서 QrEncoding 값을 사용하려면 using IronQr.Enum;를 추가합니다.
| 값 | 설명 |
|---|---|
QrEncoding.QRCode | 모든 산업에서 가장 널리 사용되는 표준 QR 코드 |
QrEncoding.MicroQRCode | 인쇄 영역이 제한된 작은 표면을 위해 설계된 컴팩트 변형 |
QrEncoding.RMQRCode | 좁고 긴 라벨 형태에 최적화된 사각형 마이크로 QR 코드 (rMQR) |
QrType는 읽기 전용이며 이미지에서 스캐너가 감지한 내용을 반영합니다. 그 값은 QR 코드가 생성된 방법에 의존하지 않습니다.
QrType의 일반적인 사용 사례는 무엇입니까?
- 물류 및 배송: 라벨이 표준 QR 코드인지 컴팩트 마이크로 QR인지를 감지하고 각각을 올바른 파싱 파이프라인으로 라우팅합니다.
- 문서 처리: 스캔된 문서가 레코드 매칭을 위해 값을 추출하기 전에 예상 형식을 포함하고 있는지 확인합니다.
- 다형식 키오스크: 하나의 스테이션에서 다양한 QR 형식을 수용하고 각각을 적절한 핸들러로 수동 개입 없이 분배합니다.
- 감사 및 준수: 디코드된 값과 함께 기호 유형을 기록하여 배치 전반에 걸쳐 입력 형식의 검증 가능한 기록을 생성합니다.
- 품질 보증: 생성된 QR 코드가 의도한 유형으로 스캔되는지 확인하여 출력이 사양과 일치하는지 확인합니다.
유형을 감지한 후 QR 코드 데이터를 읽는 방법에 대한 자세한 내용은 QR 코드 값 읽기 가이드와 전체 IronQR 기능 세트를 참조하세요.
자주 묻는 질문
C#에서 QR 코드의 유형을 어떻게 읽을 수 있나요?
IronQR 라이브러리를 사용하여 C#에서 QR 코드의 유형을 읽을 수 있습니다. 이미지를 QrImageInput에 로드하고, QrReader.Read()에 전달한 다음 반환된 QrResult의 QrType에 접근하여 QR 코드 형식을 식별하십시오.
QrResult.QrType은 무엇을 반환하나요?
QrResult.QrType은 QRCode, MicroQRCode 또는 RMQRCode와 같은 식별된 기호 체계를 식별하는 QrEncoding 열거형 값을 반환합니다. 이 속성은 IronQR로 스캔하는 동안 자동으로 채워집니다.
QR 코드 형식에 따라 처리를 어떻게 라우팅하나요?
QR 코드 형식에 따라 처리를 라우팅하려면 QrResult.QrType에 대한 switch 문을 사용하십시오. 이를 통해 QRCode, MicroQRCode 또는 RMQRCode와 같은 특정 QrEncoding 값을 처리하고 각 값을 올바른 처리 로직으로 안내할 수 있습니다.
QR 코드 유형을 감지하는 일반적인 사용 사례는 무엇인가요?
일반적인 사용 사례에는 물류 및 배송에서 QR 유형을 올바르게 라우팅하고, 문서 처리에서 예상 형식을 검증하며, 여러 형식을 지원하는 키오스크에서 다양한 입력을 처리하고, 감사/컴플라이언스에서 기호 체계 유형을 기록하는 것이 포함됩니다.
QrResult.QrType에 대한 추가 구성은 필요한가요?
추가 구성은 필요하지 않습니다. QrResult.QrType은 IronQR과 함께 QrReader.Read()를 사용할 때 자동으로 채워지며, 감지된 QrEncoding 값에 직접 접근할 수 있습니다.
QR 코드가 의도한 유형으로 스캔되는지 어떻게 확인할 수 있나요?
IronQR을 사용하여 QR 코드를 스캔하고 QrResult.QrType 값을 확인하여 의도한 QrEncoding 유형과 일치하는지 확인하여 생성된 QR 코드가 올바른지 확인하십시오.
IronQR로 예기치 않은 QR 코드 형식을 처리할 수 있나요?
네, QrResult.QrType의 switch 문에서 기본 케이스를 사용하여 예기치 않은 형식을 처리할 수 있습니다. 이를 통해 처리되지 않은 모든 형식을 잡아내고 검토를 위해 기록할 수 있습니다.
다양한 QrEncoding 값은 무엇을 나타내나요?
다양한 QrEncoding 값은 QR 코드에서 감지된 기호 체계 유형을 나타냅니다. 예를 들어 QRCode는 표준 형식이고, MicroQRCode는 소형 표면용이며, RMQRCode는 길쭉한 라벨에 최적화되어 있습니다.
QrResult.QrType은 QR 코드 유효성 검사에 어떻게 도움이 되나요?
QrResult.QrType은 스캔된 QR 코드가 데이터를 처리하기 전에 예상 형식과 일치하는지를 확인하여 데이터의 무결성과 호환성을 보장함으로써 QR 코드 유효성 검사에 도움을 줍니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.