C#에서 QR 코드 쓰기
소개
IronQR 사용하면 개발자는 인기 있는 이미지 형식에 대한 QR 코드를 생성하고 배경색, 여백, 로고 등으로 사용자 지정할 수 있으며 PDF에 추가할 수도 있습니다. 고급 사용자를 위해 오류 수정 및 버전 관리 기능도 제공합니다.
이 글에서는 IronQR 의 주요 기능을 예제와 함께 살펴보고, C#으로 QR 코드를 작성하는 방법과 프로젝트에 효과적으로 적용하는 방법을 설명합니다.
목차
- 입력 데이터
- QR 코드 내보내기
- QR 코드 옵션
- QR 코드 스타일링
오늘 무료 체험으로 프로젝트에서 IronQR 사용을 시작하십시오.
입력 데이터
텍스트, URL, 숫자
IronQR 텍스트, URL, 숫자 등 다양한 데이터 유형을 QR 코드로 변환할 수 있습니다. 마케팅 및 커뮤니케이션을 위한 QR 코드 링크나 텍스트 생성, 재고 관리를 위한 숫자 코드 생성, 또는 바이너리 데이터나 스트림을 읽기 쉬운 QR 코드로 인코딩하는 등 어떤 작업을 하든 IronQR 필요한 모든 지원을 제공합니다.
또한 API는 사용하기 쉽습니다. QrWriter 클래스는 여러 오버로드를 제공하여 다양한 유형의 데이터를 입력으로 사용하고 복잡성을 줄이며 프로세스를 단순화합니다.
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")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 코드로 변환할 수 있습니다.
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");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")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")Write 메소드는 바이트 배열과 스트림 모두를 입력으로 받는 오버로드를 가지고 있습니다. 스트림의 경우, 우리는 바이트 배열에서 MemoryStream를 생성한 다음 그것을 QR 코드로 변환할 수 있습니다. 이는 사용자가 데이터 청크를 보다 세밀하게 제어해야 할 때 유용하며, 스트림은 메모리 효율성이 더 높을 수 있습니다.
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");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")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 메소드를 사용할 때 기본 이미지 형식이 없음을 유의하세요. 인식되지 않는 확장자를 입력하거나 파일 경로에 오타가 있으면 이미지가 잘못된 확장자로 저장됩니다.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");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")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 플랫폼에서만 지원됩니다.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");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")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")IronSoftware.Drawing
System.Drawing.Common의 플랫폼 간 호환성 부족으로 인해 개발자는 플랫폼 간 애플리케이션을 유지 관리할 때 문제가 발생할 수 있습니다. IronQR은 System.Drawing.Common와 IronSoftware.Drawing 둘 다 사용할 수 있습니다.
IronQR은 IronSoftware.Drawing의 AnyBitmap 클래스를 사용하며, 이는 보편적으로 호환 가능한 비트맵 클래스이며 다음과 같이 암묵적으로 캐스팅됩니다:
System.Drawing.BitmapSystem.Drawing.ImageSkiaSharp.SKBitmapSixLabors.ImageSharpMicrosoft.Maui.Graphics.Platform.PlatformImage
이 강력한 오픈 소스 라이브러리로 IronQR은 .NET 10, .NET 9, .NET 8, .NET 7, .NET 6, .NET Core, .NET Standard, 및 .NET Framework 4.6.2+과의 플랫폼 간 지원 및 호환성을 달성합니다. 라이브러리에 대한 자세한 내용은 IronSoftware.Drawing 웹사이트를 참조하십시오.
PDF에 스탬프 찍기
IronQR 사용하면 개발자가 기존 PDF 문서에 QR 코드를 삽입하여 다른 사람들이 링크나 추가 자료에 빠르게 접근할 수 있도록 할 수 있습니다. QR 코드를 한 장 또는 여러 장에 스탬핑하는 기능이 지원됩니다.
한 페이지에 도장 찍기
QR 코드를 생성한 후 QrCode 객체에서 StampToExistingPdfPage 메소드를 호출하세요. 이 방법은 파일 경로, 좌표(x 및 y), 페이지 번호가 필요하며, PDF 파일에 암호가 설정되어 있는 경우 선택적으로 암호를 입력해야 합니다. 인수가 제공되면 해당 메서드는 QR 코드를 스캔하고 PDF 파일을 저장합니다.
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);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)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 메소드가 한 개의 페이지 번호 대신 페이지 번호 리스트를 받는다는 것입니다.
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);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)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 코드의 압축된 버전이며, 종횡비에 대한 유연성을 제공합니다.
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");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")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에서 제공하는 오류 수정 레벨은 네 단계가 있습니다:
Highest: 30% 오류 수정High: 25% 오류 수정Medium: 15% 오류 수정Low: 7% 오류 수정
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");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")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 코드를 생성할 수 있습니다.
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");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")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'로 변경했습니다.
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");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")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 코드의 크기를 조정하려면, QrStyleOptions 객체의 Dimensions 속성을 설정한 다음 Save 메소드에 전달하면 됩니다. 기본적으로 QR 코드는 300px 크기로 저장됩니다. 이 예시에서는 QR 코드의 크기를 300px 대신 600px로 저장했습니다.
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");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")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")
여백 및 테두리
가장자리와 테두리를 조정하려면 QrStyleOptions 클래스의 Margins 속성을 사용할 수 있습니다. 이 속성은 QR 코드의 모든 면의 여백을 제어하며 기본값은 10px입니다. 예시에서 우리는 여백을 20px로 설정했습니다.
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");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")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 사용자가 각 면에 서로 다른 여백을 지정할 수 있도록 하여 더욱 세밀한 제어를 가능하게 합니다.
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");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")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")색상 변경
QR 코드와 그 배경에 색상을 추가하려면 QrStyleOptions 클래스를 사용합니다. 색상을 맞춤 설정하면 QR 코드가 더욱 독특하고 눈길을 사로잡게 됩니다. Color 및 BackgroundColor 속성을 사용하여 색상을 변경할 수 있습니다. 할당할 수 있는 색상 목록을 얻기 위해 IronSoftware.Drawing를 반드시 가져오세요.
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");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")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 코드를 쉽게 맞춤 설정할 수 있습니다.
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");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")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 IronQr;
using IronSoftware.Drawing;
class Program
{
static void Main()
{
QrStyleOptions styleOptions = new QrStyleOptions
{
Logo = new QrLogo
{
Bitmap = AnyBitmap.FromFile("path/to/logo.png"),
Width = 50,
Height = 50,
CornerRadius = 5
}
};
QrCode qr = QrWriter.Write("Customized Logo Example");
AnyBitmap img = qr.Save(styleOptions);
img.SaveAs("example-customized-logo-qr.png");
}
}using IronQr;
using IronSoftware.Drawing;
class Program
{
static void Main()
{
QrStyleOptions styleOptions = new QrStyleOptions
{
Logo = new QrLogo
{
Bitmap = AnyBitmap.FromFile("path/to/logo.png"),
Width = 50,
Height = 50,
CornerRadius = 5
}
};
QrCode qr = QrWriter.Write("Customized Logo Example");
AnyBitmap img = qr.Save(styleOptions);
img.SaveAs("example-customized-logo-qr.png");
}
}Imports IronQr
Imports IronSoftware.Drawing
Module Program
Sub Main()
Dim styleOptions As New QrStyleOptions With {
.Logo = New QrLogo With {
.Bitmap = AnyBitmap.FromFile("path/to/logo.png"),
.Width = 50,
.Height = 50,
.CornerRadius = 5
}
}
Dim qr As QrCode = QrWriter.Write("Customized Logo Example")
Dim img As AnyBitmap = qr.Save(styleOptions)
img.SaveAs("example-customized-logo-qr.png")
End Sub
End ModuleImports IronQr
Imports IronSoftware.Drawing
Module Program
Sub Main()
Dim styleOptions As New QrStyleOptions With {
.Logo = New QrLogo With {
.Bitmap = AnyBitmap.FromFile("path/to/logo.png"),
.Width = 50,
.Height = 50,
.CornerRadius = 5
}
}
Dim qr As QrCode = QrWriter.Write("Customized Logo Example")
Dim img As AnyBitmap = qr.Save(styleOptions)
img.SaveAs("example-customized-logo-qr.png")
End Sub
End Module내결함성 점검
파일 형식 및 사용자 정의에 있어 광범위한 유연성을 제공할 뿐만 아니라, 디버깅 및 오류 처리 측면에서도 유연성을 제공합니다. IronQR 개발자가 예외를 처리하고 애플리케이션을 검증하기 위한 단위 테스트를 작성하는 데 사용할 수 있는 다양한 도구를 제공합니다.
체크섬
QR 코드는 때때로 손상될 수 있지만, IronQR 에는 내장된 체크섬 및 데이터 수정 기능이 있어 QR 코드가 계속 작동하도록 유지합니다. Reed-Solomon 오류 수정 알고리즘을 사용하여 QR 코드가 오류 내성을 유지할 수 있도록 합니다.
자세한 오류 메시지
IronQR 사용자가 문제를 신속하게 파악할 수 있도록 자세한 오류 메시지를 제공합니다. 이 메시지에는 특정 예외 목록이 포함되어 있어 디버깅 및 문제 해결이 더욱 간편해집니다. 아래는 라이브러리에서 사용된 IronQrException 목록입니다.
-
IronQrEncodingException:IronQrException의 하위 클래스이며 QR 코드 작성에 문제가 있을 때 발생하는 오류입니다. 예를 들어, 사용자가 빈 문자열로 QR 코드를 생성하려고 시도할 경우 이 오류가 나타납니다.
-
IronQrFileException:IronQrException의 하위 클래스이며 파일 관련 문제가 발생할 때 발생하는 오류입니다. -
IronQrPdfPasswordException:IronQrException의 하위 클래스이며 사용자가 스탬프하려고 하는 PDF가 암호로 보호되어 있을 때 발생하는 오류입니다. 또한 예시에서처럼 PDF 파일을 열 수 없는 경우와 같은 다른 PDF 관련 오류도 다룹니다.
결론
IronQR .NET 애플리케이션 내에서 QR 코드를 생성하고 사용자 정의하기 위한 포괄적인 메서드 세트를 제공합니다. 이 신뢰할 수 있는 기능을 통해 개발자는 다양한 데이터 인코딩, 시각적 스타일 및 오류 수정 수준을 사용하여 QR 코드를 쉽게 생성할 수 있습니다. 라이브러리의 다양한 출력 형식 지원 및 기존 문서에의 간단한 통합은 이를 모든 QR 코드 프로젝트에 적합한 도구로 만들었습니다. 기본 QR 코드부터 고급 브랜드 솔루션까지, IronQR 고객의 요구를 효율적으로 충족할 수 있는 유연성과 기능을 제공합니다.
자세한 내용을 알아보려면 IronQR 문서를 확인하고 무료 체험판으로 탐색을 시작하며, 라이선스 옵션을 검토하여 필요에 맞는 플랜을 확인하세요.
자주 묻는 질문
IronQR을 사용하여 C#에서 사용자 정의 오류 수정이 있는 QR 코드를 생성하려면 어떻게 해야 하나요?
IronQR은 개발자가 QrOptions 클래스의 ErrorCorrectionLevel 속성을 설정하여 QR 코드의 오류 수정 수준을 사용자 지정할 수 있도록 합니다. 필요한 오류 수정 정도에 따라 낮음, 중간, 높음, 최고 네 가지 수준 중 하나로 설정할 수 있습니다.
IronQR이 QR 코드에 다양한 유형의 데이터를 인코딩할 수 있나요?
네, IronQR은 텍스트, URL, 숫자, 이진 데이터, 스트림 등 다양한 데이터를 QR 코드로 인코딩하는 것을 지원합니다. 이러한 유연성 덕분에 웹사이트 연결이나 재고 관리 등 다양한 애플리케이션을 위한 QR 코드를 만들 수 있습니다.
IronQR을 사용하여 QR 코드를 내보낼 수 있는 파일 형식은 무엇인가요?
IronQR은 JPG, PNG, GIF, TIFF 등 여러 파일 형식으로 QR 코드를 저장할 수 있는 기능을 제공합니다. QR 코드를 저장하려면 AnyBitmap 클래스의 SaveAs 메서드를 사용하여 원하는 파일 경로와 형식을 지정합니다.
IronQR을 사용하여 QR 코드의 외관을 어떻게 사용자 지정할 수 있나요?
IronQR은 QrStyleOptions 클래스를 통해 다양한 스타일 옵션을 제공하여 QR 코드의 크기를 조정하고, 여백과 테두리를 조정하며, 색상을 변경하고, 회사 로고를 추가하여 QR 코드를 독특하고 브랜드에 맞게 만들 수 있습니다.
IronQR을 사용하여 기존 PDF 문서에 QR 코드를 찍을 수 있나요?
네, IronQR은 기존 PDF 문서에 QR 코드를 찍을 수 있는 기능을 제공합니다. StampToExistingPdfPage 또는 StampToExistingPdfPages 메서드를 사용하여 한 페이지나 여러 페이지에 QR 코드를 찍을 수 있습니다.
IronQR와 IronSoftware.Drawing을 함께 사용하는 장점은 무엇인가요?
IronSoftware.Drawing은 IronQR에 대한 크로스 플랫폼 호환성을 제공하여 다양한 .NET 버전과 플랫폼을 지원합니다. 보편적으로 호환 가능한 Bitmap 클래스인 AnyBitmap을 제공하여 여러 이미지 형식으로 변환할 수 있고, 크로스 플랫폼 애플리케이션에서 사용할 수 있습니다.
IronQR로 QR 코드를 생성할 때 예외를 어떻게 처리할 수 있나요?
IronQR은 자세한 오류 메시지를 제공하고 IronQrEncodingException 및 IronQrFileException과 같은 특정 예외 클래스를 사용하여 QR 코드 생성 중에 발생하는 오류를 식별하고 처리할 수 있도록 돕습니다. 이는 디버깅에 도움이 되며 애플리케이션의 신뢰성을 보장합니다.
IronQR을 사용하여 QR 코드의 문자 인코딩을 변경할 수 있나요?
네, QrOptions 클래스의 CharacterEncoding 속성을 사용하여 QR 코드의 문자 인코딩을 설정할 수 있습니다. 예를 들어, 특별 문자 지원을 위해 'UTF-32'를 지정하여 다양한 언어 및 스크립트에서 QR 코드의 기능을 향상시킬 수 있습니다.
IronQR에서 QR 코드 버전을 어떻게 제어할 수 있나요?
IronQR에서는 QR 코드 버전을 지정하여 다양한 양의 데이터를 저장할 수 있습니다. 이는 QrOptions 클래스의 Version 속성을 통해 제어되며, 더 높은 버전은 더 많은 데이터를 저장하여 재고 관리와 같은 애플리케이션에 적합하고, 더 낮은 버전은 더 간단한 용도에 이상적입니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.