Write QR Codes in C
소개
IronQR 사용하면 개발자는 인기 있는 이미지 형식에 대한 QR 코드를 생성하고 배경색, 여백, 로고 등으로 사용자 지정할 수 있으며 PDF에 추가할 수도 있습니다. 고급 사용자를 위해 오류 수정 및 버전 관리 기능도 제공합니다.
이 글에서는 IronQR 의 주요 기능을 예제와 함께 살펴보고, C#으로 QR 코드를 작성하는 방법과 프로젝트에 효과적으로 적용하는 방법을 설명합니다.
목차
- 입력 데이터
- QR 코드 내보내기
- QR 코드 옵션
- QR 코드 스타일링
지금 바로 무료 체험판을 통해 IronQR을 프로젝트에서 사용해 보세요.
입력 데이터
텍스트, URL, 숫자
IronQR 텍스트, URL, 숫자 등 다양한 데이터 유형을 QR 코드로 변환할 수 있습니다. 마케팅 및 커뮤니케이션을 위한 QR 코드 링크나 텍스트 생성, 재고 관리를 위한 숫자 코드 생성, 또는 바이너리 데이터나 스트림을 읽기 쉬운 QR 코드로 인코딩하는 등 어떤 작업을 하든 IronQR 필요한 모든 지원을 제공합니다.
또한 API는 사용하기 쉽습니다. QrWriter 클래스는 여러 오버로드를 제공하여 다양한 유형의 데이터를 입력으로 허용함으로써 복잡성을 줄이고 프로세스를 간소화합니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-1.cs
using IronQr;
using IronSoftware.Drawing;
string text = "Hello, World!";
string url = "https://ironsoftware.com/csharp/qr/";
string alphanumeric = "WATERSKU-12356";
// Create QR code
QrCode textQr = QrWriter.Write(text);
// Save QR code as a bitmap
AnyBitmap textQrImage = textQr.Save();
// Save QR code as file
textQrImage.SaveAs("textQr.png");
QrCode urlQr = QrWriter.Write(url);
AnyBitmap urlQrImage = urlQr.Save();
urlQrImage.SaveAs("urlQr.png");
QrCode alphanumericQr = QrWriter.Write(alphanumeric);
AnyBitmap alphanumericQrImage = alphanumericQr.Save();
alphanumericQrImage.SaveAs("alphanumericQr.png");
Imports IronQr
Imports IronSoftware.Drawing
Private text As String = "Hello, World!"
Private url As String = "https://ironsoftware.com/csharp/qr/"
Private alphanumeric As String = "WATERSKU-12356"
' Create QR code
Private textQr As QrCode = QrWriter.Write(text)
' Save QR code as a bitmap
Private textQrImage As AnyBitmap = textQr.Save()
' Save QR code as file
textQrImage.SaveAs("textQr.png")
Dim urlQr As QrCode = QrWriter.Write(url)
Dim urlQrImage As AnyBitmap = urlQr.Save()
urlQrImage.SaveAs("urlQr.png")
Dim alphanumericQr As QrCode = QrWriter.Write(alphanumeric)
Dim alphanumericQrImage As AnyBitmap = alphanumericQr.Save()
alphanumericQrImage.SaveAs("alphanumericQr.png")
바이너리 및 스트림
마찬가지로, 앞서 언급한 것과 동일한 Write 방식을 사용하여 바이너리 데이터와 스트림을 QR 코드로 변환할 수 있습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-2.cs
using IronQr;
using IronSoftware.Drawing;
using System.Text;
byte[] bytes = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/");
// Create QR code
QrCode bytesQr = QrWriter.Write(bytes);
// Save QR code as a bitmap
AnyBitmap qrImage = bytesQr.Save();
// Save QR code bitmap to file
qrImage.SaveAs("bytesQr.png");
Imports IronQr
Imports IronSoftware.Drawing
Imports System.Text
Private bytes() As Byte = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/")
' Create QR code
Private bytesQr As QrCode = QrWriter.Write(bytes)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = bytesQr.Save()
' Save QR code bitmap to file
qrImage.SaveAs("bytesQr.png")
수업 프로그램
{
정적 void Main()
{
// QR 코드 작성기 인스턴스를 생성합니다.
QrWriter writer = QrWriter.CreateQrCode();
// 이진 데이터 예시
byte[] data = { 0x01, 0x02, 0x03, 0x04 };
// QR 코드에 바이너리 데이터를 기록합니다.
writer.Write(data) .SaveAs("binary-qr.png");
// 메모리 스트림을 사용한 예시
(MemoryStream stream = new MemoryStream(data))를 사용합니다.
{ writer.Write(stream) .SaveAs("stream-qr.png"); } } }
Write 메서드에는 바이트 배열과 스트림을 모두 입력으로 받는 오버로드가 있습니다. 스트림의 경우, 바이트 배열에서 MemoryStream을 생성한 다음 이를 QR 코드로 변환할 수 있습니다. 이는 사용자가 데이터 청크를 보다 세밀하게 제어해야 할 때 유용하며, 스트림은 메모리 효율성이 더 높을 수 있습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-3.cs
using IronQr;
using IronSoftware.Drawing;
using System.IO;
using System.Text;
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/"));
// Create QR code
QrCode streamQr = QrWriter.Write(stream);
// Save QR code as a bitmap
AnyBitmap streamQrImage = streamQr.Save();
// Save QR code bitmap as file
streamQrImage.SaveAs("streamQr.png");
Imports IronQr
Imports IronSoftware.Drawing
Imports System.IO
Imports System.Text
Private stream As New MemoryStream(Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/"))
' Create QR code
Private streamQr As QrCode = QrWriter.Write(stream)
' Save QR code as a bitmap
Private streamQrImage As AnyBitmap = streamQr.Save()
' Save QR code bitmap as file
streamQrImage.SaveAs("streamQr.png")
QR 코드 내보내기
IronQR 은 다양한 파일 형식을 요구하는 여러 사용 사례에 유연하게 적용할 수 있습니다. SaveAs 메서드를 사용하여 JPG, PNG, GIF, TIFF 등 다양한 형식으로 QR 코드를 저장할 수 있습니다.
이미지로 저장
SaveAs의 AnyBitmap 메서드는 제공된 파일 경로를 기반으로 파일 형식을 자동으로 감지합니다. 이 예시에서는 .png로 끝나는 파일 경로를 지정했습니다.
SaveAs 메서드를 사용할 때, 기본 이미지 형식이 없음을 유의하십시오. 인식할 수 없는 확장자를 입력하거나 파일 경로에 오타가 있는 경우, 이미지는 잘못된 확장자로 저장됩니다.:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-4.cs
using IronQr;
using IronSoftware.Drawing;
// Create a QR code object
QrCode qr = QrWriter.Write("hello world");
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.SaveAs("qr.png");
Imports IronQr
Imports IronSoftware.Drawing
' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()
' Save QR code bitmap as file
qrImage.SaveAs("qr.png")
시스템.드로잉.이미지
이미지를 Microsoft의 System.Drawing.Images 객체로 변환하면 Bitmap 클래스를 사용하여 QR 코드를 파일 경로에 저장할 수 있습니다. 이 예제에서 Save 메서드는 QR 코드를 PNG 파일로 qrBitmap.png 경로에 저장합니다.
System.Drawing.Common은 Windows 플랫폼에서만 지원됩니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-5.cs
using IronQr;
using System.Drawing;
// Create a QR code object
QrCode qr = QrWriter.Write("hello world");
// Save QR code as a bitmap
Bitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.Save("qrBitmap.png");
Imports IronQr
Imports System.Drawing
' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")
' Save QR code as a bitmap
Private qrImage As Bitmap = qr.Save()
' Save QR code bitmap as file
qrImage.Save("qrBitmap.png")
Iron Software.드로잉
System.Drawing.Common의 크로스 플랫폼 호환성 부족으로 인해, 개발자는 크로스 플랫폼 애플리케이션을 유지 관리할 때 문제를 겪을 수 있습니다. IronQR은 System.Drawing.Common와 IronSoftware.Drawing를 모두 사용할 수 있습니다.
IronQR은 AnyBitmap의 IronSoftware.Drawing 클래스를 사용하며, 이는 범용 호환이 가능한 Bitmap 클래스로 다음으로 암시적 형변환을 수행합니다:
System.Drawing.BitmapSystem.Drawing.ImageSkiaSharp.SKBitmapSixLabors.ImageSharpMicrosoft.Maui.Graphics.Platform.PlatformImage
이 강력한 오픈 소스 라이브러리를 통해 IronQR은 크로스 플랫폼 지원과 .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard, .NET Framework 4.6.2+와의 호환성을 확보합니다. 라이브러리에 대한 자세한 내용은 IronSoftware.Drawing 웹사이트를 참조하십시오.
PDF에 스탬프 찍기
IronQR 사용하면 개발자가 기존 PDF 문서에 QR 코드를 삽입하여 다른 사람들이 링크나 추가 자료에 빠르게 접근할 수 있도록 할 수 있습니다. QR 코드를 한 장 또는 여러 장에 스탬핑하는 기능이 지원됩니다.
한 페이지에 도장 찍기
QR 코드를 생성한 후, QrCode 객체에서 StampToExistingPdfPage 메서드를 호출하십시오. 이 방법은 파일 경로, 좌표(x 및 y), 페이지 번호가 필요하며, PDF 파일에 암호가 설정되어 있는 경우 선택적으로 암호를 입력해야 합니다. 인수가 제공되면 해당 메서드는 QR 코드를 스캔하고 PDF 파일을 저장합니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-6.cs
using IronQr;
// Create a QR code object
QrCode qr = QrWriter.Write("hello world");
string filepath = "example.pdf";
int x = 100;
int y = 150;
int page = 1;
// Stamp QR code to (100, 150) of the pdf on page 1
qr.StampToExistingPdfPage(filepath, x, y, page);
Imports IronQr
' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")
Private filepath As String = "example.pdf"
Private x As Integer = 100
Private y As Integer = 150
Private page As Integer = 1
' Stamp QR code to (100, 150) of the pdf on page 1
qr.StampToExistingPdfPage(filepath, x, y, page)
여러 페이지에 스탬프 찍기
위의 예와 유사하지만, StampToExistingPdfPages 메서드는 단일 페이지 번호 대신 페이지 번호 목록을 받는다는 점이 주요 차이점입니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-7.cs
using IronQr;
using System.Collections.Generic;
// Create a QR code object
QrCode qr = QrWriter.Write("hello world");
string filepath = "example.pdf";
int x = 100;
int y = 150;
List<int> pages = new List<int>();
pages.Add(1);
pages.Add(2);
pages.Add(3);
pages.Add(4);
// Stamp QR code to (100, 150) of the pdf on pages 1-4
qr.StampToExistingPdfPages(filepath, x, y, pages);
Imports IronQr
Imports System.Collections.Generic
' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")
Private filepath As String = "example.pdf"
Private x As Integer = 100
Private y As Integer = 150
Private pages As New List(Of Integer)()
pages.Add(1)
pages.Add(2)
pages.Add(3)
pages.Add(4)
' Stamp QR code to (100, 150) of the pdf on pages 1-4
qr.StampToExistingPdfPages(filepath, x, y, pages)
두 예제 모두의 출력

QR 코드 옵션
IronQR QR 코드의 동작 및 기능을 세밀하게 조정할 수 있는 광범위한 맞춤 설정 옵션을 제공합니다. QrOptions 클래스는 버전 관리, 인코딩 유형, 문자 인코딩, 오류 수정 수준 등과 같은 여러 매개변수를 제공합니다. 이러한 옵션들을 좀 더 자세히 살펴보겠습니다.
부호화
IronQR QR 코드 생성 및 읽기 모두에 대해 다양한 유형의 QR 코드를 지원합니다. 지원되는 유형은 다음과 같습니다.
QRCode: 이는 오늘날 일반적으로 사용되는 표준 QR 코드입니다. 이 장치는 최대 7,089개의 숫자 또는 4,296개의 영숫자 문자를 저장할 수 있습니다.MicroQRCode: 표준 QR 코드의 소형 버전으로, 최대 35개의 숫자 또는 21개의 영숫자를 저장할 수 있습니다.RMQRCode: 직사각형 마이크로 QR 코드는 QR 코드의 소형 버전으로, 가로세로 비율에 유연성을 제공합니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-8.cs
using IronQr;
using IronSoftware.Drawing;
QrOptions options = new QrOptions
{
// Change encoding to micro QR code
Encoding = IronQr.Enum.QrEncoding.MicroQRCode,
};
// Create QR code
QrCode qr = QrWriter.Write("1234", options);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing
Private options As New QrOptions With {.Encoding = IronQr.Enum.QrEncoding.MicroQRCode}
' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()
' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
오류 수정
IronQR 표준 QR 오류 수정 기능을 사용하여 열악한 환경에서도 모든 QR 코드가 오류에 강하고 신뢰할 수 있도록 보장합니다. 또한 IronQR 더욱 세밀한 조정을 위해 오류 수정 수준을 완벽하게 제어할 수 있도록 해줍니다.
QrErrorCorrectionLevel에서 제공하는 4단계 오류 수정 기능이 있습니다:
Highest: 오류 수정률 30%High: 오류 수정률 25%Medium: 오류 수정률 15%Low: 7% 오류 수정
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-9.cs
using IronQr;
using IronSoftware.Drawing;
QrOptions options = new QrOptions
{
// Change error correction level to medium
ErrorCorrectionLevel = QrErrorCorrectionLevel.Medium,
};
// Create QR code
QrCode qr = QrWriter.Write("1234", options);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing
Private options As New QrOptions With {.ErrorCorrectionLevel = QrErrorCorrectionLevel.Medium}
' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()
' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
오류 수정 기능이 높을수록 QR 코드를 읽을 때 오류 허용 범위가 넓어져 오류 수정 기능이 낮은 QR 코드에 비해 낮은 해상도에서도 스캔될 가능성이 높아집니다. 사용 사례에 따라 테스트를 진행할 수 있습니다.

QR 코드 버전
QR 코드 버전을 조정하여 더 많은 데이터를 저장할 수 있습니다. 높은 버전은 재고 관리나 물류에 적합하고, 낮은 버전은 짧은 URL과 같은 작은 데이터에 적합합니다. QrOptions 객체의 Version 속성을 변경하고 이를 Write 메서드에 전달하기만 하면 필요에 따라 QR 코드를 생성할 수 있습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-10.cs
using IronQr;
using IronSoftware.Drawing;
QrOptions options = new QrOptions
{
// Change QR code version to 40
Version = 40,
};
// Create QR code
QrCode qr = QrWriter.Write("1234", options);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing
Private options As New QrOptions With {.Version = 40}
' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()
' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")

출력 결과에서 볼 수 있듯이, QR 코드 버전 40은 버전 5에 비해 훨씬 복잡하고 밀도가 높습니다.
낮은 버전의 경우 더욱 정밀한 스캔이 필요하며, 고해상도 스캐너 없이는 스캔하기 어려울 수 있습니다. 하지만 고해상도 버전일수록 저해상도 카메라로도 스캔하기가 더 쉽습니다. 용량에 따른 QR 버전 선택에 대한 자세한 안내는 QR 버전 목록을 참조하십시오.
문자 인코딩
이 옵션은 QR 코드 인코딩 방식을 결정합니다. 예시에서는 기본 문자 인코딩인 'ISO-8859-1'을 'UTF-32'로 변경했습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-11.cs
using IronQr;
using IronSoftware.Drawing;
QrOptions options = new QrOptions
{
// Change character encoding to UTF-32
CharacterEncoding = "UTF-32"
};
// Create QR code
QrCode qr = QrWriter.Write("1234", options);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();
// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing
Private options As New QrOptions With {.CharacterEncoding = "UTF-32"}
' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()
' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
QR 코드 스타일링
IronQR 사용하기 쉬운 방법과 입력 데이터 처리의 유연성 외에도 QR 코드를 고유하게 만들 수 있는 다양한 맞춤 설정 및 스타일 옵션을 제공합니다. QrStyleOptions 클래스는 QR 코드의 모든 측면을 사용자 지정할 수 있는 다양한 매개변수를 제공합니다. 가능한 옵션들을 살펴보겠습니다.
크기 조정
QR 코드의 크기를 조정하려면 Dimensions 객체의 QrStyleOptions 속성을 설정한 후 Save 메서드에 전달하면 됩니다. 기본적으로 QR 코드는 300px 크기로 저장됩니다. 이 예시에서는 QR 코드의 크기를 300px 대신 600px로 저장했습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-12.cs
using IronQr;
using IronSoftware.Drawing;
QrStyleOptions styleOptions = new QrStyleOptions()
{
// Change the dimensions to 600px
Dimensions = 600,
};
string url = "https://ironsoftware.com/csharp/qr/";
// Create QR code
QrCode qr = QrWriter.Write(url);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);
// Save QR code bitmap as file
qrImage.SaveAs("qrURLResized.png");
Imports IronQr
Imports IronSoftware.Drawing
Private styleOptions As New QrStyleOptions() With {.Dimensions = 600}
Private url As String = "https://ironsoftware.com/csharp/qr/"
' Create QR code
Private qr As QrCode = QrWriter.Write(url)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)
' Save QR code bitmap as file
qrImage.SaveAs("qrURLResized.png")

여백 및 테두리
여백과 테두리를 조정하려면 Margins 클래스의 QrStyleOptions 속성을 사용할 수 있습니다. 이 속성은 QR 코드의 모든 면의 여백을 제어하며 기본값은 10px입니다. 예시에서 우리는 여백을 20px로 설정했습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-13.cs
using IronQr;
using IronSoftware.Drawing;
QrStyleOptions styleOptions = new QrStyleOptions()
{
// Change margins to 20px
Margins = 20
};
string url = "https://ironsoftware.com/csharp/qr/";
// Create QR code
QrCode qr = QrWriter.Write(url);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);
// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");
Imports IronQr
Imports IronSoftware.Drawing
Private styleOptions As New QrStyleOptions() With {.Margins = 20}
Private url As String = "https://ironsoftware.com/csharp/qr/"
' Create QR code
Private qr As QrCode = QrWriter.Write(url)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)
' Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png")

각 변의 여백을 변경하세요
IronQR 사용자가 각 면에 서로 다른 여백을 지정할 수 있도록 하여 더욱 세밀한 제어를 가능하게 합니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-14.cs
using IronQr;
using IronSoftware.Drawing;
QrStyleOptions styleOptions = new QrStyleOptions()
{
// Change margins
MarginBottom = 30,
MarginTop = 100,
MarginRight = 40,
MarginLeft = 20,
};
string url = "https://ironsoftware.com/csharp/qr/";
// Create QR code
QrCode qr = QrWriter.Write(url);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);
// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");
Imports IronQr
Imports IronSoftware.Drawing
Private styleOptions As New QrStyleOptions() With {
.MarginBottom = 30,
.MarginTop = 100,
.MarginRight = 40,
.MarginLeft = 20
}
Private url As String = "https://ironsoftware.com/csharp/qr/"
' Create QR code
Private qr As QrCode = QrWriter.Write(url)
' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)
' Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png")
색상 변경
QrStyleOptions 클래스를 사용하여 QR 코드와 그 배경에 색상을 적용할 수 있습니다. 색상을 맞춤 설정하면 QR 코드가 더욱 독특하고 눈길을 사로잡게 됩니다. Color 및 BackgroundColor 속성을 사용하여 색상을 변경할 수 있습니다. 할당 가능한 색상 목록을 확인하려면 IronSoftware.Drawing를 반드시 포함하십시오.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-15.cs
using IronQr;
using IronSoftware.Drawing;
// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");
// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
Logo = new QrLogo(logo, 50, 50, 10),
};
string url = "https://ironsoftware.com/csharp/qr/";
// Create QR code
QrCode qr = QrWriter.Write(url);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);
// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");
Imports IronQr
Imports IronSoftware.Drawing
' Load new logo image
Dim logo As AnyBitmap = AnyBitmap.FromFile("sample.png")
' Add new logo to QR code style options
Dim styleOptions As New QrStyleOptions() With {
.Logo = New QrLogo(logo, 50, 50, 10)
}
Dim url As String = "https://ironsoftware.com/csharp/qr/"
' Create QR code
Dim qr As QrCode = QrWriter.Write(url)
' Save QR code as a bitmap
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
' Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png")

로고 추가
색상과 크기 외에도 QR 코드에 회사 로고를 적용할 수 있습니다. 이를 통해 사용자는 QR 코드를 즉시 인식하고 브랜드와 연관시킬 수 있습니다. Logo 속성을 사용하면 회사 로고를 추가하여 QR 코드를 쉽게 맞춤 설정할 수 있습니다.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-15.cs
using IronQr;
using IronSoftware.Drawing;
// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");
// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
Logo = new QrLogo(logo, 50, 50, 10),
};
string url = "https://ironsoftware.com/csharp/qr/";
// Create QR code
QrCode qr = QrWriter.Write(url);
// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);
// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");
Imports IronQr
Imports IronSoftware.Drawing
' Load new logo image
Dim logo As AnyBitmap = AnyBitmap.FromFile("sample.png")
' Add new logo to QR code style options
Dim styleOptions As New QrStyleOptions() With {
.Logo = New QrLogo(logo, 50, 50, 10)
}
Dim url As String = "https://ironsoftware.com/csharp/qr/"
' Create QR code
Dim qr As QrCode = QrWriter.Write(url)
' Save QR code as a bitmap
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
' Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png")

로고를 맞춤 설정하세요
QrLogo 클래스를 사용하면 로고의 모양을 더욱 세밀하게 사용자 지정할 수 있습니다. 아래는 이용 가능한 매물 목록입니다.
Bitmap: 로고로 사용하고자 하는 이미지를 나타냅니다.Width: 로고의 너비를 나타냅니다. 기본값은 0입니다.Height: 로고의 높이를 나타냅니다. 기본값은 0입니다.CornerRadius: 로고 모서리를 둥글게 처리할 반경을 나타냅니다. 기본값은 0으로 설정되어 있어 로고의 모서리가 사각형이 됩니다.
using IronQRCode;
using IronSoftware.Drawing;
수업 프로그램
{
정적 void Main()
{
`QrStyleOptions` styleOptions = new `QrStyleOptions`
{
`Logo` = new `QrLogo`
{
`Bitmap` = `AnyBitmap.FromBitmap`("path/to/logo.png"),
`Width` = 50,
`Height` = 50,
`CornerRadius` = 5
}
};
`QrCode` qr = `QrWriter.CreateQrCode`()
.Write("Customized Logo Example");
qr.SaveAs("example-customized-logo-qr.png", styleOptions);
}
}
using IronQRCode;
using IronSoftware.Drawing;
수업 프로그램
{
정적 void Main()
{
`QrStyleOptions` styleOptions = new `QrStyleOptions`
{
`Logo` = new `QrLogo`
{
`Bitmap` = `AnyBitmap.FromBitmap`("path/to/logo.png"),
`Width` = 50,
`Height` = 50,
`CornerRadius` = 5
}
};
`QrCode` qr = `QrWriter.CreateQrCode`()
.Write("Customized Logo Example");
qr.SaveAs("example-customized-logo-qr.png", styleOptions);
}
}
Imports IronQRCode
Imports IronSoftware.Drawing
Module Program
Sub Main()
Dim styleOptions As New QrStyleOptions With {
.Logo = New QrLogo With {
.Bitmap = AnyBitmap.FromBitmap("path/to/logo.png"),
.Width = 50,
.Height = 50,
.CornerRadius = 5
}
}
Dim qr As QrCode = QrWriter.CreateQrCode().Write("Customized Logo Example")
qr.SaveAs("example-customized-logo-qr.png", styleOptions)
End Sub
End Module
내결함성 점검
파일 형식 및 사용자 정의에 있어 광범위한 유연성을 제공할 뿐만 아니라, 디버깅 및 오류 처리 측면에서도 유연성을 제공합니다. IronQR 개발자가 예외를 처리하고 애플리케이션을 검증하기 위한 단위 테스트를 작성하는 데 사용할 수 있는 다양한 도구를 제공합니다.
체크섬
QR 코드는 때때로 손상될 수 있지만, IronQR 에는 내장된 체크섬 및 데이터 수정 기능이 있어 QR 코드가 계속 작동하도록 유지합니다. 이 시스템은 리드-솔로몬 오류 수정 알고리즘을 사용하여 QR 코드가 오류에 강인하게 작동하도록 보장합니다.
자세한 오류 메시지
IronQR 사용자가 문제를 신속하게 파악할 수 있도록 자세한 오류 메시지를 제공합니다. 이 메시지에는 특정 예외 목록이 포함되어 있어 디버깅 및 문제 해결이 더욱 간편해집니다. 아래는 이 라이브러리에서 사용하는 IronQrException 목록입니다.
IronQrEncodingException:IronQrException의 하위 클래스로, QR 코드 작성에 문제가 있을 때 발생하는 오류입니다. 예를 들어, 사용자가 빈 문자열로 QR 코드를 생성하려고 시도할 경우 이 오류가 나타납니다.

-
IronQrFileException:IronQrException의 하위 클래스로, 파일 관련 문제가 발생할 때 이 오류가 발생합니다. IronQrPdfPasswordExcception:IronQrException의 하위 클래스인 이 오류는 사용자가 스탬프를 찍으려는 PDF 파일이 암호로 보호되어 있는데, 암호가 입력되지 않았거나 잘못된 암호가 입력된 경우에 발생합니다. 또한 예시에서처럼 PDF 파일을 열 수 없는 경우와 같은 다른 PDF 관련 오류도 다룹니다.

결론
IronQR .NET 애플리케이션 내에서 QR 코드를 생성하고 사용자 정의하기 위한 포괄적인 메서드 세트를 제공합니다. 이 플랫폼은 강력한 기능을 갖추고 있어 개발자가 다양한 데이터 인코딩, 시각적 스타일 및 오류 수정 수준을 적용하여 QR 코드를 손쉽게 생성할 수 있습니다. 이 라이브러리는 다양한 출력 형식을 지원하고 기존 문서와 원활하게 통합되므로 모든 QR 코드 프로젝트에 활용할 수 있는 다재다능한 도구입니다. 기본 QR 코드부터 고급 브랜드 솔루션까지, IronQR 고객의 요구를 효율적으로 충족할 수 있는 유연성과 기능을 제공합니다.
더 자세히 알아보려면 IronQR 문서를 참조하고, 무료 평가판을 사용해 보고, 라이선스 옵션을 검토하여 필요에 가장 적합한 플랜을 선택하세요.
자주 묻는 질문
C#에서 QR 코드를 생성하는 방법은 무엇인가요?
IronQR에서 제공하는 QrWriter 클래스를 사용하면 C#에서 QR 코드를 생성할 수 있습니다. 이 클래스를 사용하면 QR 코드에 데이터를 입력하고 다양한 이미지 형식으로 저장할 수 있습니다. Write 메서드를 사용하여 데이터를 인코딩하고 SaveAs 메서드를 사용하여 QR 코드를 출력하면 됩니다.
QR 코드에 어떤 종류의 맞춤 설정을 적용할 수 있나요?
IronQR을 사용하면 QR 코드의 색상 변경, 로고 추가, 크기 조정 및 여백 조정을 통해 QR 코드를 사용자 지정할 수 있습니다. 이러한 사용자 지정을 적용하려면 QrStyleOptions 클래스를 사용하십시오.
C#을 사용하여 PDF에 QR 코드를 삽입할 수 있나요?
네, IronQR의 StampToExistingPdfPage 또는 StampToExistingPdfPages 메서드를 사용하면 PDF에 QR 코드를 삽입할 수 있습니다. 이 메서드를 통해 QR 코드가 나타날 위치와 페이지를 지정할 수 있습니다.
QR 코드 생성 시 발생하는 오류는 어떻게 처리해야 하나요?
IronQR은 IronQrEncodingException , IronQrFileException , IronQrPdfPasswordException 과 같은 오류 메시지를 제공하여 디버깅 및 문제 해결을 지원하는 강력한 오류 처리 기능을 갖추고 있습니다.
QR 코드를 어떤 형식으로 내보낼 수 있나요?
IronQR을 사용하면 QR 코드를 JPG, PNG, GIF, TIFF 등 다양한 형식으로 내보낼 수 있습니다. '다른 SaveAs 기능을 사용하면 QR 코드 출력에 원하는 형식을 지정할 수 있습니다.
이 라이브러리는 크로스 플랫폼 개발을 지원합니까?
네, IronQR은 IronSoftware.Drawing 라이브러리를 통해 크로스 플랫폼 개발을 지원하므로 다양한 .NET 버전 및 플랫폼과 호환됩니다.
QR 코드에 로고를 추가하여 브랜딩하는 것이 가능할까요?
IronQR을 사용하면 QrStyleOptions 클래스의 Logo 속성을 설정하여 QR 코드에 로고를 추가할 수 있으며, 이를 통해 사용자 지정 로고 모양으로 브랜드화된 QR 코드를 만들 수 있습니다.
QR 코드에서 오류 수정의 목적은 무엇인가요?
IronQR에서 지원하는 QR 코드 오류 수정 기능은 QR 코드가 부분적으로 손상되었더라도 읽을 수 있도록 보장합니다. 이 기능은 다양한 사용 사례에 맞춰 최고, 높음, 중간, 낮음의 네 가지 수준의 수정 레벨을 제공합니다.
QR 코드에는 어떤 데이터 유형을 인코딩할 수 있습니까?
IronQR은 텍스트, URL, 숫자, 바이너리 데이터 및 스트림을 포함한 다양한 데이터 유형을 QR 코드에 인코딩할 수 있으므로 표현할 수 있는 데이터의 종류에 유연성을 제공합니다.
C#에서 URL을 포함하는 QR 코드를 어떻게 만들 수 있나요?
C#에서 URL을 포함하는 QR 코드를 생성하려면 IronQR의 QrWriter 클래스를 사용합니다. Write 메서드를 사용하여 URL을 인코딩하고 SaveAs 메서드를 사용하여 QR 코드를 이미지로 저장합니다.

