C#에서 QR 코드 체크섬을 검증하고 내결함성을 적용하는 방법
인쇄된 라벨, 카메라 촬영 이미지, 스캔 문서 등 실제 입력을 처리하는 QR 코드 파이프라인에서는 손상이 심해 디코딩할 수 없는 심볼과 체크섬 검사는 통과했지만 업무 규칙 검증에는 실패하는 결과를 마주할 수 있습니다.
리드-솔로몬 오류 정정은 디코딩 과정에서 물리적 손상으로 인한 오류를 자동으로 정정합니다. 심볼을 복구할 수 없으면 부분 결과 없이 빈 컬렉션이 반환됩니다. 추가 처리 전에는 애플리케이션에서 별도로 디코딩된 값이 비어 있지 않은지, 예상 형식과 일치하는지, 유효한 URI를 포함하는지 등을 확인합니다.
이 가이드에서는 IronQR 라이브러리로 QR 코드 체크섬을 검증하고 내결함성 검사를 적용하는 방법을 설명합니다.
빠른 시작: QR 코드 체크섬 검증QR 코드를 읽고 디코딩이 성공했는지 확인합니다. 결과가 비어 있지 않으면 리드-솔로몬 체크섬 검사를 통과한 것입니다.
-
1IronQR를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
using IronQr; using IronSoftware.Drawing; var reader = new QrReader(); IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("label.png"))); if (!results.Any()) { Console.WriteLine("No QR code detected or decoding failed."); return; } Console.WriteLine(results.First().Value);Imports IronQr Imports IronSoftware.Drawing Dim reader = New QrReader() Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("label.png"))) If Not results.Any() Then Console.WriteLine("No QR code detected or decoding failed.") Return End If Console.WriteLine(results.First().Value)Imports IronQr Imports IronSoftware.Drawing Dim reader = New QrReader() Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("label.png"))) If Not results.Any() Then Console.WriteLine("No QR code detected or decoding failed.") Return End If Console.WriteLine(results.First().Value) -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronQR 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- QR 코드 체크섬을 검증할 수 있는 IronQR C# 라이브러리를 다운로드합니다.
QrImageInput으로 이미지를 불러옵니다.QrReader.Read를 호출하여 이미지를 디코딩하고 리드-솔로몬 검사를 자동으로 실행합니다.- 결과 컬렉션을 확인합니다. 컬렉션이 비어 있으면 디코딩에 실패한 것입니다.
- 디코딩된 값을 후속 처리 단계로 전달하기 전에 애플리케이션 요구 사항을 충족하는지 확인합니다.
QR 코드 체크섬 검증
QR 코드는 인코딩된 데이터의 손상을 감지하고 복구하기 위해 리드-솔로몬 오류 정정을 사용합니다. 오류 정정 수준(Low 7%, Medium 15%, Quartile 25%, High 30%)에 따라 손실되더라도 복구할 수 있는 코드워드의 비율이 달라집니다.
QR 코드를 읽을 때는 디코딩 과정에서 내부적으로 체크섬을 검증합니다. QrResult 클래스에는 신뢰도 속성이 없으며, 컬렉션에 결과가 있으면 체크섬 검사를 통과한 것입니다. 디코딩에 실패하면 컬렉션이 비어 있습니다.
입력
제품 라벨에 넣은 QR 코드로, 오류 정정 수준을 Medium으로 설정해 https://ironsoftware.com/을 인코딩했습니다. 운송 중에 취급되거나 가벼운 흠집이 생길 수 있는 라벨을 예로 듭니다.

using IronQr;
using IronSoftware.Drawing;
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("damaged-label.png")));
// Reed-Solomon decoding is pass/fail — presence in results means valid checksum
if (!results.Any())
{
// Decoding failed entirely — damage exceeded the error correction capacity
Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.");
return;
}
foreach (QrResult result in results)
{
// Decoded successfully — validate the content matches expected format
if (string.IsNullOrWhiteSpace(result.Value))
{
Console.WriteLine("QR decoded but produced an empty value.");
continue;
}
Console.WriteLine($"Valid QR: {result.Value}");
}using IronQr;
using IronSoftware.Drawing;
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("damaged-label.png")));
// Reed-Solomon decoding is pass/fail — presence in results means valid checksum
if (!results.Any())
{
// Decoding failed entirely — damage exceeded the error correction capacity
Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.");
return;
}
foreach (QrResult result in results)
{
// Decoded successfully — validate the content matches expected format
if (string.IsNullOrWhiteSpace(result.Value))
{
Console.WriteLine("QR decoded but produced an empty value.");
continue;
}
Console.WriteLine($"Valid QR: {result.Value}");
}Imports IronQr
Imports IronSoftware.Drawing
Dim reader = New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("damaged-label.png")))
' Reed-Solomon decoding is pass/fail — presence in results means valid checksum
If Not results.Any() Then
' Decoding failed entirely — damage exceeded the error correction capacity
Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.")
Return
End If
For Each result As QrResult In results
' Decoded successfully — validate the content matches expected format
If String.IsNullOrWhiteSpace(result.Value) Then
Console.WriteLine("QR decoded but produced an empty value.")
Continue For
End If
Console.WriteLine($"Valid QR: {result.Value}")
NextImports IronQr
Imports IronSoftware.Drawing
Dim reader = New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("damaged-label.png")))
' Reed-Solomon decoding is pass/fail — presence in results means valid checksum
If Not results.Any() Then
' Decoding failed entirely — damage exceeded the error correction capacity
Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.")
Return
End If
For Each result As QrResult In results
' Decoded successfully — validate the content matches expected format
If String.IsNullOrWhiteSpace(result.Value) Then
Console.WriteLine("QR decoded but produced an empty value.")
Continue For
End If
Console.WriteLine($"Valid QR: {result.Value}")
Next출력
콘솔에는 디코딩된 값 https://ironsoftware.com/이(가) 표시되며, 리드-솔로몬 디코딩에 성공하여 페이로드가 온전히 복구되었음을 확인합니다.

물리적 손상에 더 잘 견디도록 하려면 오류 정정 수준을 높여 QR 코드를 생성하세요. High 수준에서는 심볼이 커지는 대신 최대 30%의 데이터 손실을 복구할 수 있습니다.
QR 코드를 읽을 때 인코딩 형식 확인하기
IronQR은 표준 QR, 마이크로 QR, 직사각형 마이크로 QR의 세 가지 QR 인코딩 형식을 지원합니다. 스캐너는 읽는 동안 자동으로 형식을 감지합니다. 스캔한 후 QrResult.QrType 필드는 감지된 형식을 열거형 값으로 제공합니다.
스캔 모드는 속도와 정확도의 균형을 결정합니다. Auto는 기계 학습 기반 감지와 기본 스캔을 함께 사용하고, OnlyDetectionModel은 빠른 처리를 위해 ML 모델만 사용합니다. OnlyBasicScan은 전처리된 고품질 이미지에서 ML을 사용하지 않습니다.
입력
PNG 제품 라벨(왼쪽)과 JPEG 촬영 이미지(오른쪽)를 사용하여 두 가지 일반적인 입력 유형에서 QR 인코딩 형식을 감지하는 방법을 보여줍니다.

제품 라벨 (PNG)

카메라 캡처(JPEG)
using IronQr;
using IronSoftware.Drawing;
using IronQr.Enum;
// Read from an image file with ML + classic scan (default)
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("product-label.png")));
foreach (QrResult result in results)
{
// Inspect the detected QR format
Console.WriteLine($"Format: {result.QrType}"); // QRCode, MicroQRCode, or RMQRCode
Console.WriteLine($"Value: {result.Value}");
// Url is non-null only if Value is a valid URI
if (result.Url != null)
{
Console.WriteLine($"URI: {result.Url.AbsoluteUri}");
}
// Corner coordinates for positional context
Console.WriteLine($"Corners: {result.Points.Length} points detected");
}
// Read from a bitmap with ML-only mode for faster throughput
var bitmap = AnyBitmap.FromFile("camera-capture.jpg");
var fastResults = reader.Read(new QrImageInput(bitmap, QrScanMode.OnlyDetectionModel));using IronQr;
using IronSoftware.Drawing;
using IronQr.Enum;
// Read from an image file with ML + classic scan (default)
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("product-label.png")));
foreach (QrResult result in results)
{
// Inspect the detected QR format
Console.WriteLine($"Format: {result.QrType}"); // QRCode, MicroQRCode, or RMQRCode
Console.WriteLine($"Value: {result.Value}");
// Url is non-null only if Value is a valid URI
if (result.Url != null)
{
Console.WriteLine($"URI: {result.Url.AbsoluteUri}");
}
// Corner coordinates for positional context
Console.WriteLine($"Corners: {result.Points.Length} points detected");
}
// Read from a bitmap with ML-only mode for faster throughput
var bitmap = AnyBitmap.FromFile("camera-capture.jpg");
var fastResults = reader.Read(new QrImageInput(bitmap, QrScanMode.OnlyDetectionModel));Imports IronQr
Imports IronSoftware.Drawing
Imports IronQr.Enum
' Read from an image file with ML + classic scan (default)
Dim reader As New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("product-label.png")))
For Each result As QrResult In results
' Inspect the detected QR format
Console.WriteLine($"Format: {result.QrType}") ' QRCode, MicroQRCode, or RMQRCode
Console.WriteLine($"Value: {result.Value}")
' Url is non-null only if Value is a valid URI
If result.Url IsNot Nothing Then
Console.WriteLine($"URI: {result.Url.AbsoluteUri}")
End If
' Corner coordinates for positional context
Console.WriteLine($"Corners: {result.Points.Length} points detected")
Next
' Read from a bitmap with ML-only mode for faster throughput
Dim bitmap = AnyBitmap.FromFile("camera-capture.jpg")
Dim fastResults = reader.Read(New QrImageInput(bitmap, QrScanMode.OnlyDetectionModel))Imports IronQr
Imports IronSoftware.Drawing
Imports IronQr.Enum
' Read from an image file with ML + classic scan (default)
Dim reader As New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile("product-label.png")))
For Each result As QrResult In results
' Inspect the detected QR format
Console.WriteLine($"Format: {result.QrType}") ' QRCode, MicroQRCode, or RMQRCode
Console.WriteLine($"Value: {result.Value}")
' Url is non-null only if Value is a valid URI
If result.Url IsNot Nothing Then
Console.WriteLine($"URI: {result.Url.AbsoluteUri}")
End If
' Corner coordinates for positional context
Console.WriteLine($"Corners: {result.Points.Length} points detected")
Next
' Read from a bitmap with ML-only mode for faster throughput
Dim bitmap = AnyBitmap.FromFile("camera-capture.jpg")
Dim fastResults = reader.Read(New QrImageInput(bitmap, QrScanMode.OnlyDetectionModel))출력
콘솔에는 제품 라벨에 대해 감지된 형식, 디코딩된 값, 확인된 URI 및 모서리 개수가 표시되고, 이어서 카메라 캡처에 대한 고속 스캔 결과 개수가 표시됩니다.

응용 프로그램이 특정 형식을 요구할 때 QrType 필드는 유용합니다. 예를 들어, 표준 QR 코드만 생성하는 창고 관리 시스템은 예상치 못한 마이크로 QR 코드 또는 직사각형 마이크로 QR 코드 감지를 걸러낼 수 있습니다. 이러한 코드는 노이즈 또는 관련 없는 라벨을 나타낼 수 있습니다. 각 형식은 용량 특성이 다릅니다. 표준 QR 코드는 최대 7,089개의 숫자 문자를 지원하고, 마이크로 QR 코드는 최대 35개의 숫자를 지원하며, 직사각형 마이크로 QR 코드는 제한된 라벨 공간에 적합한 직사각형 형태를 제공합니다.
QR 코드 결과에 null 검사 적용
QR 코드를 찾지 못하면 QrReader.Read는 빈 컬렉션을 반환하며 null을 반환하는 경우는 없습니다. 다만 개별 결과의 속성은 별도로 검증해야 합니다. 예를 들어 Value는 비어 있을 수 있고, 디코딩된 문자열이 유효한 URI가 아니면 Url은 null을 반환합니다.
데이터를 다른 시스템에 전달하기 전에 컬렉션의 항목 수, 값의 무결성, 유형 또는 URI의 유효성을 확인합니다.
입력
QR 코드가 없는 빈 흰색 이미지로, 기계 판독 가능한 라벨이 없는 페이지가 섞여 있는 문서 묶음의 한 페이지를 나타냅니다.

using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
using System.Linq;
public static class QrValidator
{
public static List<QrResult> GetValidResults(
string imagePath,
QrEncoding? expectedFormat = null)
{
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile(imagePath)));
// Guard: no QR codes detected
if (!results.Any())
return new List<QrResult>();
return results
.Where(r => !string.IsNullOrWhiteSpace(r.Value))
.Where(r => expectedFormat == null || r.QrType == expectedFormat)
.ToList();
}
}
// Usage — only accept standard QR codes with non-empty values
var validated = QrValidator.GetValidResults(
"shipping-manifest.png",
expectedFormat: QrEncoding.QRCode);
if (validated.Count == 0)
{
Console.WriteLine("No valid QR codes found for processing.");
return;
}
foreach (var qr in validated)
{
// Safe for downstream: value is non-empty, format is verified
SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri);
}using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
using System.Linq;
public static class QrValidator
{
public static List<QrResult> GetValidResults(
string imagePath,
QrEncoding? expectedFormat = null)
{
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile(imagePath)));
// Guard: no QR codes detected
if (!results.Any())
return new List<QrResult>();
return results
.Where(r => !string.IsNullOrWhiteSpace(r.Value))
.Where(r => expectedFormat == null || r.QrType == expectedFormat)
.ToList();
}
}
// Usage — only accept standard QR codes with non-empty values
var validated = QrValidator.GetValidResults(
"shipping-manifest.png",
expectedFormat: QrEncoding.QRCode);
if (validated.Count == 0)
{
Console.WriteLine("No valid QR codes found for processing.");
return;
}
foreach (var qr in validated)
{
// Safe for downstream: value is non-empty, format is verified
SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri);
}Imports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Public Module QrValidator
Public Function GetValidResults(
imagePath As String,
Optional expectedFormat As QrEncoding? = Nothing) As List(Of QrResult)
Dim reader = New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile(imagePath)))
' Guard: no QR codes detected
If Not results.Any() Then
Return New List(Of QrResult)()
End If
Return results.
Where(Function(r) Not String.IsNullOrWhiteSpace(r.Value)).
Where(Function(r) expectedFormat Is Nothing OrElse r.QrType = expectedFormat).
ToList()
End Function
End Module
' Usage — only accept standard QR codes with non-empty values
Dim validated = QrValidator.GetValidResults(
"shipping-manifest.png",
expectedFormat:=QrEncoding.QRCode)
If validated.Count = 0 Then
Console.WriteLine("No valid QR codes found for processing.")
Return
End If
For Each qr In validated
' Safe for downstream: value is non-empty, format is verified
SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri)
Next qrImports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Public Module QrValidator
Public Function GetValidResults(
imagePath As String,
Optional expectedFormat As QrEncoding? = Nothing) As List(Of QrResult)
Dim reader = New QrReader()
Dim results As IEnumerable(Of QrResult) = reader.Read(New QrImageInput(AnyBitmap.FromFile(imagePath)))
' Guard: no QR codes detected
If Not results.Any() Then
Return New List(Of QrResult)()
End If
Return results.
Where(Function(r) Not String.IsNullOrWhiteSpace(r.Value)).
Where(Function(r) expectedFormat Is Nothing OrElse r.QrType = expectedFormat).
ToList()
End Function
End Module
' Usage — only accept standard QR codes with non-empty values
Dim validated = QrValidator.GetValidResults(
"shipping-manifest.png",
expectedFormat:=QrEncoding.QRCode)
If validated.Count = 0 Then
Console.WriteLine("No valid QR codes found for processing.")
Return
End If
For Each qr In validated
' Safe for downstream: value is non-empty, format is verified
SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri)
Next qr출력
콘솔에는 검증기의 빈 결과 응답이 표시됩니다. QR 코드가 감지되지 않았으므로 컬렉션이 비어 있고 데이터가 하위 처리 단계로 넘어가지 않습니다.
검증기는 결과가 없으면 빈 목록을 반환하므로 호출하는 쪽에서 null을 검사할 필요가 없습니다. 선택적 expectedFormat 매개변수를 지정하면 예상 형식과 일치하는 결과만 반환됩니다. Url 속성은 null 조건부 연산자를 사용해 URI인 페이로드와 URI가 아닌 페이로드를 모두 안전하게 처리합니다.
비동기 작업에서도 ReadAsync 호출이 완료될 때까지 기다린 뒤 반환된 컬렉션에 동일한 검사를 적용합니다.
추가 자료
- 오류 정정 수준: QR 코드 생성 시 손상에 대한 복원력과 오류 정정 수준 설정.
- QR 코드 읽기 방법: 입력 형식 옵션 및 읽기 패턴.
- QrResult API 레퍼런스: 전체 속성 목록.
- 고급 스캔 예제: 스캔 모드 구성.
프로덕션에 배포할 준비가 되면 라이선스 옵션을 확인하세요.
ChecksumFaultToleranceTest 콘솔 앱 프로젝트 전체를 다운로드하세요.
자주 묻는 질문
C#에서 QR 코드 체크섬을 유효성 검사하는 것이 왜 중요한가요?
QR 코드 체크섬을 유효성 검사하는 것은 QR 코드에 인코딩된 데이터의 무결성을 보장하기 위해 중요합니다. IronQR은 리드-솔로몬 오류 수정을 사용하여 디코딩 중 물리적 손상을 자동으로 해결하며, 반환된 데이터가 정확하고 신뢰할 수 있도록 보장합니다.
IronQR에서 리드-솔로몬 오류 수정은 어떻게 작동하나요?
IronQR의 리드-솔로몬 오류 수정은 인코딩된 데이터의 손상을 특정 수준까지 감지하고 수리합니다. 이 수정 수준은 낮음, 중간, 쿼틸, 높음일 수 있으며 디코딩 중 회복할 수 있는 오류의 백분율을 결정합니다.
QR 코드가 IronQR로 디코딩되지 않으면 어떻게 해야 하나요?
QR 코드가 IronQR로 디코딩되지 않는 경우, 오류 수정 용량을 초과하는 손상 때문일 수 있습니다. 코드를 다시 스캔하거나, 더 높은 오류 수정 수준으로 QR 코드를 생성하거나, 입력 이미지 품질을 개선할 수 있는지 확인해보세요.
IronQR이 다양한 QR 인코딩 형식을 처리할 수 있나요?
예, IronQR은 표준 QR, 마이크로 QR, 직사각형 마이크로 QR을 포함한 다양한 QR 인코딩 형식을 지원합니다. 스캐너는 읽는 동안 형식을 자동으로 감지하여 효율적이고 유연한 QR 코드 처리를 가능하게 합니다.
IronQR을 사용하여 이미지에서 QR 코드가 감지되지 않으면 어떻게 되나요?
IronQR을 사용하여 QR 코드가 감지되지 않으면 QrReader.Read 메서드는 빈 컬렉션을 반환합니다. 이는 디코딩이 실패했으며 실행 가능한 QR 데이터가 없음을 나타냅니다.
QR 코드 데이터가 내 애플리케이션 요구사항에 적합한지 어떻게 확인할 수 있나요?
디코딩 후에는 예상 형식을 확인하거나 내용이 비어 있지 않으며 유효한 URI와 일치하는지 확인하는 등 특정 애플리케이션 요구사항과 디코딩된 값을 비교하여 유효성을 검사해야 합니다.
IronQR이 QR 코드 판독 중 형식 인식을 제공하나요?
예, IronQR은 판독 중 QR 코드 형식을 감지하여 형식 인식을 제공합니다. 형식을 QrResult 객체의 일부로 반환하여 애플리케이션이 특정 형식을 적절하게 처리할 수 있게 합니다.
`QrResult` 클래스는 IronQR에서 어떤 역할을 하나요?
IronQR의 QrResult 클래스는 QR 코드 판독에서 디코딩된 결과를 나타냅니다. 디코딩된 값, 감지된 QR 유형, 그리고 선택적으로 값이 유효한 URL인 경우 URI와 같은 속성을 제공합니다.
IronQR은 QR 코드에 대한 물리적 손상을 어떻게 처리하나요?
IronQR은 디코딩 중 QR 코드의 경미한 손상을 자동으로 수정하여 물리적 손상에 더 강하고 데이터 무결성을 보장하기 위해 리드-솔로몬 오류 수정을 사용합니다.
IronQR이 QR 코드를 비동기적으로 유효성 검사할 수 있나요?
예, IronQR은 비동기 워크플로를 지원합니다. ReadAsync를 사용하여 비차단 QR 코드 판독을 수행하면서 유사한 유효성 검사 패턴을 결과에 적용할 수 있습니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.