How to Generate Barcode Images in C# .NET Applications
Professional 바코드 이미지를 빠르게 생성해야 합니까? 이 튜토리얼에서는 IronBarcode를 사용하여 바코드를 생성, 사용자 지정 및 내보내는 방법을 단계별로 설명합니다. 간단한 한 줄 구현부터 바코드 모양을 완벽하게 제어할 수 있는 고급 스타일링 기법까지 다룹니다.
빠른 시작: BarCode 이미지를 즉시 생성하고 저장하기
IronBarcode를 사용하면 단 한 번의 간단한 호출만으로 BarCode 이미지를 생성하고 내보낼 수 있습니다. 텍스트에 CreateBarcode 메서드를 사용하고, 형식과 크기를 선택한 다음 SaveAsPng를 호출하세요. 복잡한 설정은 필요하지 않습니다.
-
NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/BarCode 설치하기
PM > Install-Package BarCode -
다음 코드 조각을 복사하여 실행하세요.
IronBarCode.BarcodeWriter.CreateBarcode("Hello123", BarcodeWriterEncoding.Co/de128, 200, 100).SaveAsPng("barcode.png"); -
실제 운영 환경에서 테스트할 수 있도록 배포하세요.
무료 체험판으로 오늘 프로젝트에서 IronBarcode 사용 시작하기
최소 워크플로 (5단계)
- NuGet 패키지 관리자를 통해 IronBarcode 설치
- 한 줄의 코드로 간단한 BarCode 생성하기
- BARCODE에 사용자 지정 스타일 및 주석 적용
- BarCode를 이미지, PDF 또는 HTML로 내보내기
- 효율적인 BarCode 생성을 위한 Fluent API 사용
How Do I Install a Barcode Generator Library in C#?
NuGet 패키지 관리자를 사용하면 IronBarcode를 단 몇 초 만에 설치할 수 있습니다. 패키지 관리자 콘솔을 통해 직접 설치하거나 DLL 파일을 수동으로 다운로드할 수 있습니다.
Install-Package BarCode
IronBarcode for .NET은 .NET 개발자를 위한 포괄적인 BarCode 생성 기능을 제공합니다
How Can I Generate a Simple Barcode Using C#?
첫 번째 BarCode를 만드는 데는 단 두 줄의 코드만 필요합니다. 아래 예제는 표준 Code128 BARCODE를 생성하여 이미지 파일로 저장하는 방법을 보여줍니다.
using IronBarCode;
// Create a barcode with your desired content and encoding type
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Co/de128);
// Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png");
// Optional: Open the generated image in your default viewer
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("myBarcode.png") { UseShellExecute = true });
using IronBarCode;
// Create a barcode with your desired content and encoding type
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Co/de128);
// Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png");
// Optional: Open the generated image in your default viewer
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("myBarcode.png") { UseShellExecute = true });
Imports IronBarCode
Imports System.Diagnostics
' Create a barcode with your desired content and encoding type
Dim myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128)
' Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png")
' Optional: Open the generated image in your default viewer
Process.Start(New ProcessStartInfo("myBarcode.png") With {.UseShellExecute = True})
BarcodeWriter.CreateBarcode() 메서드는 BARCODE 생성을 위한 진입점입니다. 이 함수는 인코딩할 데이터와 BarcodeWriterEncoding 열거형에서 지정된 BARCODE 형식이라는 두 가지 매개변수를 받습니다. IronBarcode는 Code128, Code39, EAN13, UPCA, PDF417, @@-를 지원합니다.-CODE-175--@@, QRCode 코드를 포함한 모든 주요 바코드 형식을 지원합니다.
생성된 GeneratedBarcode 객체는 다양한 내보내기 옵션을 제공합니다. 다양한 이미지 형식(PNG, JPEG, GIF, TIFF)으로 저장하거나, PDF로 내보내거나, 애플리케이션에서 추가 처리를 위해 System.Drawing.Bitmap 형식으로 불러올 수도 있습니다.
*A Code128 barcode generated with IronBarcode displaying a URL*
생성된 BARCODE의 모양을 사용자 지정할 수 있나요?
IronBarcode는 기본적인 BarCode 생성을 훨씬 뛰어넘는 광범위한 사용자 지정 옵션을 제공합니다. 주석을 추가하고, 색상을 조정하며, 여백을 설정하고, BARCODE 외관의 모든 측면을 제어할 수 있습니다.
using IronBarCode;
using IronSoftware.Drawing;
// Create a QR code with advanced styling options
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com/csharp/barcode",
BarcodeWriterEncoding.QRCode
);
// Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:");
// Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode();
// Set consistent margins around the barcode
myBarCode.SetMargins(100);
// Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple);
// Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html");
using IronBarCode;
using IronSoftware.Drawing;
// Create a QR code with advanced styling options
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com/csharp/barcode",
BarcodeWriterEncoding.QRCode
);
// Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:");
// Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode();
// Set consistent margins around the barcode
myBarCode.SetMargins(100);
// Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple);
// Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html");
Imports IronBarCode
Imports IronSoftware.Drawing
' Create a QR code with advanced styling options
Private myBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode)
' Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:")
' Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode()
' Set consistent margins around the barcode
myBarCode.SetMargins(100)
' Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple)
' Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html")
GeneratedBarcode 클래스는 사용자 지정을 위한 다양한 메서드 세트를 제공합니다:
- 주석: BARCODE 주변에 사용자 지정 레이블이나 지침을 추가하려면
AddAnnotationTextAboveBarcode()및AddAnnotationTextBelowBarcode()을 사용하십시오. - 값 표시:
AddBarcodeValueTextBelowBarcode()메서드는 인코딩된 데이터를 사람이 읽을 수 있는 형식으로 자동으로 표시합니다. - 공백: 적절한 스캔 및 시각적 효과를 보장하기 위해
SetMargins()을 사용하여 공백을 제어하십시오 - 색상:
ChangeBarCodeColor()및ChangeBackgroundColor()을 사용하여 전경색과 배경색을 변경합니다. - 내보내기 옵션: 이미지 파일, PDF 또는 독립형 HTML 문서로 저장
*사용자 정의 색상과 주석 텍스트가 포함된 스타일링된 QR 코드*자세한 사용자 지정 옵션은 사용 가능한 모든 스타일링 메서드와 속성을 다루는 GeneratedBarcode 클래스 문서를 참조하십시오.
한 줄의 코드로 BarCode를 생성하고 내보내려면 어떻게 해야 하나요?
IronBarcode는 메서드 체이닝을 가능하게 하여 더 간결하고 가독성 높은 코드를 작성할 수 있도록 하는 플루언트(Fluent) API 디자인 패턴을 구현합니다. 이 방법은 BARCODE에 여러 가지 변환을 적용할 때 특히 유용합니다.
using IronBarCode;
using IronSoftware.Drawing;
// Generate, style, and convert a barcode in a single statement
string value = "https://ironsoftware.com/csharp/barcode";
// Create PDF417 barcode with chained operations
AnyBitmap barcodeBitmap = BarcodeWriter
.CreateBarcode(value, BarcodeWriterEncoding.PDF417) // Create PDF417 barcode
.ResizeTo(300, 200) // Set specific dimensions
.SetMargins(10) // Add 10px margins
.ToBitmap(); // Convert to bitmap
// Convert to System.Drawing.Bitmap for legacy compatibility
System.Drawing.Bitmap legacyBitmap = barcodeBitmap;
using IronBarCode;
using IronSoftware.Drawing;
// Generate, style, and convert a barcode in a single statement
string value = "https://ironsoftware.com/csharp/barcode";
// Create PDF417 barcode with chained operations
AnyBitmap barcodeBitmap = BarcodeWriter
.CreateBarcode(value, BarcodeWriterEncoding.PDF417) // Create PDF417 barcode
.ResizeTo(300, 200) // Set specific dimensions
.SetMargins(10) // Add 10px margins
.ToBitmap(); // Convert to bitmap
// Convert to System.Drawing.Bitmap for legacy compatibility
System.Drawing.Bitmap legacyBitmap = barcodeBitmap;
Imports IronBarCode
Imports IronSoftware.Drawing
' Generate, style, and convert a barcode in a single statement
Private value As String = "https://ironsoftware.com/csharp/barcode"
' Create PDF417 barcode with chained operations
Private barcodeBitmap As AnyBitmap = BarcodeWriter.CreateBarcode(value, BarcodeWriterEncoding.PDF417).ResizeTo(300, 200).SetMargins(10).ToBitmap() ' Convert to bitmap
' Convert to System.Drawing.Bitmap for legacy compatibility
Private legacyBitmap As System.Drawing.Bitmap = barcodeBitmap
유연한 API 패턴은 다음과 같은 여러 이점을 제공합니다:
- 가독성: 연산들을 자연어처럼 읽히는 논리적 순서로 연결하십시오
- 효율성: 변수 선언 및 중간 단계를 줄입니다
- 유연성: 코드 구조를 변경하지 않고도 작업을 쉽게 추가하거나 제거할 수 있습니다
일반적인 유연한 연산에는 다음이 포함됩니다:
ResizeTo(): 정확한 BARCODE 치수 제어SetMargins(): 일관된 공백 추가ChangeBarCodeColor(): 모양 수정AddAnnotationTextAboveBarcode(): 설명 텍스트 포함ToBitmap(),SaveAsPng(),SaveAsPdf(): 다양한 형식으로 내보내기
*A PDF417 barcode generated using fluent method chaining*
IronBarcode는 어떤 바코드 형식을 지원합니까?
IronBarcode는 BarcodeWriterEncoding 열거형을 통해 포괄적인 BARCODE 형식 생성을 지원합니다. 지원되는 형식은 다음과 같습니다:
1D BARCODE: Code128, Code39, Code93, Codabar, ITF, MSI, Plessey, UPCA, UPCE, EAN8, EAN13
2D BARCODE: QRCode, DataMatrix, PDF417, Aztec, MaxiCode
전문 형식: IntelligentMail, DataBar, DataBarExpanded 및 다양한 GS1 표준
각 형식은 고유한 특성과 사용 사례를 가지고 있습니다. 예를 들어, QRCode 코드는 URL 및 대량의 데이터를 저장하는 데 탁월한 반면, EAN13는 소매 제품의 표준입니다. 응용 프로그램에 적합한 BarCode 형식을 선택하는 방법에 대해 자세히 알아보세요.
생성된 BARCODE가 읽히는지 어떻게 확인할 수 있나요?
BarCode 구현에는 품질 보증이 매우 중요합니다. IronBarcode에는 생성된 BARCODE가 스캔 가능하도록 보장하는 내장 검증 기능이 포함되어 있습니다:
// Generate and verify a barcode
GeneratedBarcode myBarcode = BarcodeWriter
.CreateBarcode("TEST123", BarcodeWriterEncoding.Co/de128)
.ResizeTo(200, 100)
.ChangeBarCodeColor(Color.DarkBlue);
// Verify the barcode is still readable after modifications
bool isReadable = myBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
// Generate and verify a barcode
GeneratedBarcode myBarcode = BarcodeWriter
.CreateBarcode("TEST123", BarcodeWriterEncoding.Co/de128)
.ResizeTo(200, 100)
.ChangeBarCodeColor(Color.DarkBlue);
// Verify the barcode is still readable after modifications
bool isReadable = myBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
Imports System.Drawing
' Generate and verify a barcode
Dim myBarcode As GeneratedBarcode = BarcodeWriter _
.CreateBarcode("TEST123", BarcodeWriterEncoding.Code128) _
.ResizeTo(200, 100) _
.ChangeBarCodeColor(Color.DarkBlue)
' Verify the barcode is still readable after modifications
Dim isReadable As Boolean = myBarcode.Verify()
Console.WriteLine($"Barcode verification: {(If(isReadable, "PASS", "FAIL"))}")
Verify() 메서드는 크기 조정이나 색상 변경과 같은 변환을 적용한 후에도 BARCODE가 기계 판독이 가능한지 확인합니다. 비표준 색상이나 매우 작은 글자 크기를 사용할 때 특히 중요합니다.
BARCODE 생성 예시는 어디에서 더 찾아볼 수 있나요?
BarCode 생성 기능을 확장하려면 다음 추가 리소스를 확인해 보세요:
소스 코드 및 예제
이 튜토리얼의 전체 소스 코드를 다운로드하세요:
고급 주제
- 로고가 포함된 QR 코드 생성 - QR 코드에 브랜드 로고 추가
- BarCode 스타일 가이드 - 고급 사용자 지정 기법 마스터하기
- 이미지에서 BarCode 읽기 - BarCode 스캔으로 작업 완료
- 일괄 BarCode 생성 - 여러 BarCode를 효율적으로 생성합니다
API 문서
BarcodeWriter클래스 참조 - 전체 메서드 문서GeneratedBarcode클래스 참조 - 모든 사용자 지정 옵션BarcodeWriterEncodingEnum - 지원되는 BarCode 형식
Professional BarCode
IronBarcode는 BARCODE 생성을 간편하게 만들어 주면서도 Professional 애플리케이션에 필요한 유연성을 제공합니다. 간단한 제품 코드부터 사용자 정의 스타일이 적용된 복잡한 2D BARCODE에 이르기까지, IronBarcode는 최소한의 코드로 모든 것을 처리합니다.
지금 바로 IronBarcode를 다운로드하여 몇 분 만에 BarCode를 생성해 보세요. 적합한 라이선스 선택에 도움이 필요하신가요? 라이선스 옵션을 확인하거나 무료 체험판 키를 요청하여 실제 운영 환경에서 IronBarcode를 테스트해 보십시오.
자주 묻는 질문
C#에서 바코드 이미지를 어떻게 생성할 수 있나요?
C#에서 바코드 이미지를 생성하려면 IronBarcode의 BarcodeWriter.CreateBarcode() 메서드를 사용할 수 있습니다. 이 메서드를 사용하면 데이터와 바코드 형식을 지정한 다음 SaveAsPng() 와 같은 메서드를 사용하여 PNG 또는 JPEG와 같은 형식으로 이미지를 저장할 수 있습니다.
.NET 프로젝트에 IronBarcode를 설치하는 단계는 무엇인가요?
Visual Studio의 NuGet 패키지 관리자를 사용하여 .NET 프로젝트에 IronBarcode를 설치할 수 있습니다. 또는 IronBarcode 웹사이트에서 DLL 파일을 다운로드하여 프로젝트 참조에 추가할 수도 있습니다.
C#에서 바코드를 PDF 파일로 내보내는 방법은 무엇인가요?
IronBarcode는 GeneratedBarcode 클래스의 SaveAsPdf() 메서드를 사용하여 바코드를 PDF로 내보낼 수 있도록 지원하며, 바코드를 PDF 형식으로 저장하는 간편한 방법을 제공합니다.
C#에서 바코드에 사용할 수 있는 사용자 지정 옵션에는 어떤 것들이 있습니까?
IronBarcode는 ChangeBarCodeColor() 사용하여 바코드 색상을 변경하거나, AddAnnotationTextAboveBarcode() 를 사용하여 텍스트 주석을 추가하거나, SetMargins() 를 사용하여 여백을 설정하는 등 광범위한 사용자 지정 옵션을 제공합니다.
단 한 줄의 코드로 바코드를 빠르게 생성하고 스타일을 지정하는 방법은 무엇인가요?
IronBarcode의 Fluent API를 사용하면 메서드 체이닝을 통해 한 줄로 바코드를 생성하고 스타일을 지정할 수 있습니다. 예: BarcodeWriter.CreateBarcode(data, encoding).ResizeTo(300, 200).SetMargins(10).SaveAsPng(path) .
수정 후에도 바코드가 스캔 가능한지 어떻게 확인할 수 있나요?
스타일 지정이나 크기 조정 후 바코드의 스캔 가능성을 확인하려면 GeneratedBarcode 객체의 Verify() 메서드를 사용하여 기계 판독 가능 여부를 검사하십시오.
C#으로 로고가 포함된 QR 코드를 생성할 수 있나요?
네, IronBarcode는 QRCodeWriter 클래스를 사용하여 로고가 내장된 QR 코드 생성을 지원하며, 이 클래스에는 로고 삽입 및 향상된 오류 수정 기능이 포함되어 있습니다.
C#에서 여러 개의 바코드를 효율적으로 생성하는 과정은 무엇인가요?
IronBarcode를 사용하면 C#에서 여러 개의 바코드를 효율적으로 생성할 수 있습니다. IronBarcode는 배치 처리를 지원하며, 루프 또는 병렬 처리를 통해 대용량 바코드 생성을 처리할 수 있습니다.
C#에서 바코드를 내보낼 때 사용할 수 있는 파일 형식은 무엇인가요?
IronBarcode는 PNG, JPEG, GIF, TIFF, BMP, PDF, HTML 등 다양한 형식으로 바코드 내보내기를 지원하여 다양한 애플리케이션 요구 사항에 맞는 유연성을 제공합니다.
C#에서 바코드 아래에 사람이 읽을 수 있는 텍스트를 추가하려면 어떻게 해야 하나요?
C#에서 바코드 아래에 사람이 읽을 수 있는 텍스트를 추가하려면 AddBarcodeValueTextBelowBarcode() 메서드를 사용하면 됩니다. 이 메서드는 인코딩된 값을 텍스트 형식으로 바코드 이미지 아래에 자동으로 표시합니다.

