C#에서 OcrProgress 추적을 사용하는 방법

IronBarcode를 사용하여 C#의 .NET에서 바코드를 커스터마이징하고 스타일링하기

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcode는 C#에서 색상을 변경하고 크기를 조정하며 주석을 추가하는 등 단순한 메서드 호출로 바코드를 사용자 지정할 수 있게 합니다. ChangeBarCodeColor()ResizeTo()와 같은 메서드 호출로 전체 스타일링 제어가 가능합니다.

수년 동안 바코드 사용은 점점 인기를 끌며, 데이터, 아이디, 웹페이지 URL을 저장하는 등 다양한 애플리케이션에서 사용됩니다. 일부 애플리케이션에서는 제품에 바코드가 눈에 띄게 되어, 스타일링 옵션에 대한 수요가 증가했습니다. 따라서 PDF417, Aztec, IntelligentMail, MaxiCode, DataMatrix 등과 같은 독특한 외형을 가진 일부 바코드 유형이 개발되었습니다. 지원되는 포맷의 포괄적인 목록은 지원 바코드 포맷 문서를 참조하세요.

또한 IronBarcode는 사용자에게 바코드 색상, 바코드 크기 조정, 배경 색상과 같은 세부 사항을 포함한 추가 스타일링 옵션을 제공합니다. 이것은 우리의 오픈 소스 라이브러리, IronDrawing의 도움으로 가능해졌습니다. 이들 스타일링 기능들은 IronBarcode의 포괄적인 바코드 생성 기능에 구축된 것입니다.

빠른 시작: 바코드 색상 및 배경 사용자 정의

여기 IronBarcode를 사용하여 바코드의 막대와 배경에 사용자가 정의한 색상을 빠르게 적용하는 방법을 보여주는 간단한 예제가 있습니다. 체인 호출 하나만으로 스타일링된 바코드를 생성하는 것이 얼마나 쉬운지를 알 수 있습니다. 더 고급 예제는 우리의 C# 바코드 이미지 생성기 튜토리얼을 참조하세요.

  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/BarCode 설치하기

    PM > Install-Package BarCode
  2. 다음 코드 조각을 복사하여 실행하세요.

    IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128)
        .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue)
        .ChangeBackgroundColor(IronSoftware.Drawing.Color.White)
        .SaveAsImage("styled.png");
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronBarcode 사용 시작하기

    arrow pointer

바코드 크기 조정을 어떻게 하나요?

ResizeTo 메서드는 언제 사용해야 하나요?

바코드 크기 조정은 IronBarcode를 통해 사용자가 달성할 수 있는 커스터마이징의 한 측면입니다. 이 기능을 사용하려면 ResizeTo 메서드를 호출하고 바코드의 새로운 폭과 높이를 픽셀(px) 단위로 입력하면 됩니다. 이 작업은 바코드의 손실 없는 재렌더링을 트리거합니다. 이 메서드는 바코드의 치수를 조정하면서 품질을 유지하므로, 특정 레이아웃이나 인쇄 크기에 바코드를 맞춰야 하는 상황에 적합합니다.

참고해 주세요바코드를 읽을 수 없을 정도로 작은 값은 무시됩니다.

using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcode(string barcodeText, int newWidth, int newHeight)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode
                     .ResizeTo(newWidth, newHeight)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode.png");
    }

    // Example usage with different size requirements
    public static void ResizeForDifferentFormats()
    {
        var barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128);

        // Resize for product label
        barcode.ResizeTo(200, 50).SaveAsImage("product_label.png");

        // Resize for shipping label
        barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png");

        // Resize for inventory tag
        barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png");
    }
}
using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcode(string barcodeText, int newWidth, int newHeight)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode
                     .ResizeTo(newWidth, newHeight)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode.png");
    }

    // Example usage with different size requirements
    public static void ResizeForDifferentFormats()
    {
        var barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128);

        // Resize for product label
        barcode.ResizeTo(200, 50).SaveAsImage("product_label.png");

        // Resize for shipping label
        barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png");

        // Resize for inventory tag
        barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png");
    }
}
$vbLabelText   $csharpLabel

ResizeTo 메서드는 GeneratedBarcode 객체에서 호출할 수 있습니다. 다양한 출력 형식 작업 시, PDF로 바코드 만들기 가이드를 참조하실 수도 있습니다. 아래는 위 코드 스니펫 실행으로 생성된 바코드 이미지입니다.

Original barcode with standard dimensions before resize operation
Resized barcode showing clear black and white vertical bars after dimension modification

1D 바코드에 ResizeToMil 메서드를 사용하는 이유는 무엇인가요?

IronBarcode에서 제공하는 크기 조정의 또 다른 측면은 ResizeToMil 메서드입니다. ResizeTo 메서드와 달리 이 메서드는 다음 구성 요소를 조정합니다:

  • 바코드 요소: 가장 좁은 바코드 요소의 폭은 천분의 인치(mil)로 측정됩니다.
  • 높이: 바코드의 높이로, 인치로 측정됩니다(기본값은 1인치).
  • 해상도: 인치당 도트 수(DPI)(기본값은 96 DPI).

이 메서드는 특히 1D 바코드에 적합하며 정확한 측정이 중요한 산업 응용 프로그램에서 일반적으로 사용됩니다. mil 측정 시스템은 다양한 스캐너 및 인쇄 조건에서 일관된 바코드 가독성을 보장하는 산업 표준입니다.

using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcodeToMil(string barcodeText, int elementWidthMil, int heightInches, int dpi = 96)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode to mil
                     .ResizeToMil(elementWidthMil, heightInches, dpi)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode_mil.png");
    }

    // Example for different industrial standards
    public static void CreateIndustrialBarcodes()
    {
        // Standard retail barcode (10 mil width, 1 inch height)
        BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128)
                     .ResizeToMil(10, 1, 300)
                     .SaveAsImage("retail_barcode.png");

        // High-density warehouse barcode (5 mil width, 0.5 inch height)
        BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128)
                     .ResizeToMil(5, 0.5f, 600)
                     .SaveAsImage("warehouse_barcode.png");

        // Large shipping barcode (15 mil width, 2 inch height)
        BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128)
                     .ResizeToMil(15, 2, 200)
                     .SaveAsImage("shipping_barcode.png");
    }
}
using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcodeToMil(string barcodeText, int elementWidthMil, int heightInches, int dpi = 96)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode to mil
                     .ResizeToMil(elementWidthMil, heightInches, dpi)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode_mil.png");
    }

    // Example for different industrial standards
    public static void CreateIndustrialBarcodes()
    {
        // Standard retail barcode (10 mil width, 1 inch height)
        BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128)
                     .ResizeToMil(10, 1, 300)
                     .SaveAsImage("retail_barcode.png");

        // High-density warehouse barcode (5 mil width, 0.5 inch height)
        BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128)
                     .ResizeToMil(5, 0.5f, 600)
                     .SaveAsImage("warehouse_barcode.png");

        // Large shipping barcode (15 mil width, 2 inch height)
        BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128)
                     .ResizeToMil(15, 2, 200)
                     .SaveAsImage("shipping_barcode.png");
    }
}
$vbLabelText   $csharpLabel

이 메서드는 GeneratedBarcode 객체에서도 호출할 수 있습니다. 정확한 바코드 크기 설정에 대한 자세한 내용은 우리 바코드 여백 설정 가이드를 참조하세요. 아래 이미지에서는 ResizeToMil 메서드를 적용한 효과를 볼 수 있습니다: 바코드 가장자리의 여백이 제거되고 가장 좁은 요소와 바코드의 높이가 메서드에 제공된 매개변수 값에 따라 조정됩니다.

Original barcode with standard dimensions before ResizeToMil method is applied
Linear barcode showing result after ResizeToMil method application with vertical black and white bars

바코드와 배경 색상을 어떻게 변경하나요?

바코드 스타일링에서 가장 많이 요구되는 기능 중 하나는 바코드와 배경 색상을 모두 변경할 수 있는 기능입니다. IronDrawing 덕분에 IronBarcode는 이 기능을 제공합니다. ChangeBarCodeColorChangeBackgroundColor 메서드를 GeneratedBarcode 객체에서 사용하여 사용자는 바코드와 그 배경의 색상을 변경할 수 있습니다. 이 기능은 특히 브랜딩 목적이나 특별 이벤트 또는 제품 라인을 위한 테마 바코드 생성 시 유용합니다.

using IronBarCode;
using IronSoftware.Drawing; // Required for color manipulation

public class BarcodeColorChanger
{
    public static void ChangeBarcodeColors(string barcodeText, Color barcodeColor, Color backgroundColor)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Change the barcode color
        barcode.ChangeBarCodeColor(barcodeColor);

        // Change the background color
        barcode.ChangeBackgroundColor(backgroundColor);

        // Save the colored barcode
        barcode.SaveAsImage("colored_barcode.png");
    }

    // Example: Create branded barcodes with company colors
    public static void CreateBrandedBarcodes()
    {
        // Company brand colors example
        var barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128);

        // Apply brand colors
        barcode.ChangeBarCodeColor(Color.FromHex("#1E3A8A")) // Company blue
               .ChangeBackgroundColor(Color.FromHex("#F3F4F6")) // Light gray background
               .SaveAsImage("branded_barcode.png");

        // Create seasonal variation
        var seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128);
        seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen)
                       .ChangeBackgroundColor(Color.LightYellow)
                       .SaveAsImage("seasonal_barcode.png");
    }
}
using IronBarCode;
using IronSoftware.Drawing; // Required for color manipulation

public class BarcodeColorChanger
{
    public static void ChangeBarcodeColors(string barcodeText, Color barcodeColor, Color backgroundColor)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Change the barcode color
        barcode.ChangeBarCodeColor(barcodeColor);

        // Change the background color
        barcode.ChangeBackgroundColor(backgroundColor);

        // Save the colored barcode
        barcode.SaveAsImage("colored_barcode.png");
    }

    // Example: Create branded barcodes with company colors
    public static void CreateBrandedBarcodes()
    {
        // Company brand colors example
        var barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128);

        // Apply brand colors
        barcode.ChangeBarCodeColor(Color.FromHex("#1E3A8A")) // Company blue
               .ChangeBackgroundColor(Color.FromHex("#F3F4F6")) // Light gray background
               .SaveAsImage("branded_barcode.png");

        // Create seasonal variation
        var seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128);
        seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen)
                       .ChangeBackgroundColor(Color.LightYellow)
                       .SaveAsImage("seasonal_barcode.png");
    }
}
$vbLabelText   $csharpLabel

색상이 사용된 바코드 작업 시, 가독성을 위해 바코드와 배경 색상 간의 충분한 대조를 유지하는 것이 중요합니다. QR 코드에 특화된 더 많은 스타일링 옵션은 QR 코드 스타일 커스터마이징 튜토리얼을 참고하세요.

록색 배경과 황갈색 전경색을 사용한 QR 코드, 바코드 색상 사용자 정의를 보여줌

바코드에 주석을 어떻게 추가하나요?

IronBarcode는 바코드 주석을 추가하고 스타일링하는 옵션도 제공합니다. 주석 스타일링은 IronDrawing의 기능을 통해 지원되며, 주석 색상 및 글꼴 편집을 포함합니다. 주석은 기계 판독 가능한 바코드 옆에 인간이 읽을 수 있는 정보를 제공하여 재고 관리, 제품 라벨링 및 배송 애플리케이션에서 필수적입니다.

using IronBarCode;
using IronSoftware.Drawing; // Required for font and color manipulation

public class BarcodeAnnotator
{
    public static void AnnotateBarcode(string barcodeText, string annotationText, Font annotationFont, Color annotationColor, float annotationSpacing)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Add annotation above the barcode
        barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing);

        // Add barcode value text below the barcode
        barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing);

        // Save the annotated barcode
        barcode.SaveAsImage("annotated_barcode.png");
    }

    // Example: Create product label with annotations
    public static void CreateProductLabel()
    {
        var productCode = "PRD-12345-XL";
        var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);

        // Define fonts for different purposes
        var titleFont = new Font("Arial", FontStyle.Bold, 14);
        var valueFont = new Font("Arial", FontStyle.Regular, 12);

        // Add product name above
        barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5);

        // Add product code below
        barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3);

        // Apply additional styling
        barcode.ResizeTo(250, 80)
               .SaveAsImage("product_label_annotated.png");
    }
}
using IronBarCode;
using IronSoftware.Drawing; // Required for font and color manipulation

public class BarcodeAnnotator
{
    public static void AnnotateBarcode(string barcodeText, string annotationText, Font annotationFont, Color annotationColor, float annotationSpacing)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Add annotation above the barcode
        barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing);

        // Add barcode value text below the barcode
        barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing);

        // Save the annotated barcode
        barcode.SaveAsImage("annotated_barcode.png");
    }

    // Example: Create product label with annotations
    public static void CreateProductLabel()
    {
        var productCode = "PRD-12345-XL";
        var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);

        // Define fonts for different purposes
        var titleFont = new Font("Arial", FontStyle.Bold, 14);
        var valueFont = new Font("Arial", FontStyle.Regular, 12);

        // Add product name above
        barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5);

        // Add product code below
        barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3);

        // Apply additional styling
        barcode.ResizeTo(250, 80)
               .SaveAsImage("product_label_annotated.png");
    }
}
$vbLabelText   $csharpLabel
IronBarcode에 의해 생성된 철 파란색과 베이지 색상 QR 코드에는 ironsoftware.com URL이 포함되어 있습니다.

이전 코드 조각의 확장으로서 바코드 위와 아래의 주석용 폰트로 사용할 두 개의 새로운 IronSoftware.Drawing.Font 객체를 인스턴스화합니다. 글꼴 가족만 있으면 글꼴을 인스턴스화할 수 있으며, 추가로 사이즈나 스타일과 같은 속성을 지정하여 더 많은 제어를 할 수 있습니다.

  • AddAnnotationTextAboveBarcode: 바코드 위에 사용자 정의 주석 텍스트를 추가합니다.
  • AddBarcodeValueTextBelowBarcode: 바코드 아래에 바코드 값을 추가합니다.

이 두 메서드는 같은 매개변수를 허용합니다: IronSoftware.Drawing.Font 객체들, IronSoftware.Drawing.Color 객체, 그리고 바코드와 텍스트 사이의 간격입니다. 또한, AddAnnotationTextAboveBarcode 메서드는 바코드 위에 사용자 정의 텍스트를 추가하기 위해 주석 텍스트용 문자열이 필요합니다.

IronBarcode는 바코드를 스타일링하기 위한 다양한 사용자 정의 옵션을 제공합니다. 주석에 유니코드 지원이 필요한 애플리케이션의 경우, 우리의 유니코드 바코드 작성 안내서를 확인하세요. QR 코드 사용자 정의에 대해 더 알고 싶다면 'QR 코드 스타일 사용자 정의 및 로고 추가 방법'을 참조하세요. 다양한 포맷으로 스타일링된 바코드를 내보내려면, 우리의 HTML로 바코드 생성 튜토리얼을 탐색하세요.

자주 묻는 질문

C#에서 바코드 색상을 어떻게 변경할 수 있나요?

IronBarcode는 바코드 색상을 쉽게 사용자 지정할 수 있는 ChangeBarCodeColor() 메서드를 제공합니다. 바코드를 생성한 후 이 메서드를 체이닝하여 IronSoftware.Drawing.Color 팔레트에서 원하는 색상을 적용하면 바코드의 시각적 모양을 완벽하게 제어할 수 있습니다.

바코드의 품질 저하 없이 크기를 조정하려면 어떤 방법을 사용해야 할까요?

IronBarcode의 ResizeTo() 메서드를 사용하여 품질 손실 없이 바코드 크기를 조정할 수 있습니다. 이 메서드는 지정된 픽셀 너비와 높이로 바코드를 손실 없이 다시 렌더링하여, 특정 레이아웃이나 인쇄 요구 사항에 맞게 크기를 조정하면서도 선명도를 유지합니다.

바코드의 배경색을 사용자 지정할 수 있나요?

예, IronBarcode는 ChangeBackgroundColor() 메서드를 사용하여 바코드 배경을 사용자 지정할 수 있도록 지원합니다. 이 기능을 통해 IronSoftware.Drawing.Color 팔레트를 사용하여 원하는 배경색을 설정할 수 있으므로 디자인 요구 사항에 완벽하게 통합할 수 있습니다.

어떤 바코드 형식이 고유한 스타일링 옵션을 지원합니까?

IronBarcode는 PDF417, Aztec, IntelligentMail, MaxiCode, DataMatrix 등 다양한 바코드 형식을 지원하며, 각 형식은 고유한 시각적 특징을 가지고 있습니다. IronBarcode의 스타일링 기능을 통해 다양한 사용자 정의 옵션도 제공합니다.

바코드에 주석을 추가하려면 어떻게 해야 하나요?

IronBarcode를 사용하면 바코드 위아래에 주석을 추가하여 가독성을 높이고 추가적인 맥락 정보를 제공할 수 있습니다. 이 기능은 바코드 옆에 사람이 읽을 수 있는 텍스트, 제품 코드 또는 기타 식별 정보를 추가하는 데 특히 유용합니다.

ResizeTo 메서드와 ResizeToMil 메서드의 차이점은 무엇인가요?

IronBarcode는 두 가지 크기 조정 방법을 제공합니다. 하나는 픽셀 단위로 크기 조정을 하고 손실 없이 다시 렌더링하는 `ResizeTo()`이고, 다른 하나는 밀(mil) 단위로 바코드 요소의 크기를 조정하는 `ResizeToMil()`입니다. 두 방법 모두 서로 다른 측정 요구 사항을 충족하면서 품질을 유지합니다.

하릴 하시미 빈 오마르
소프트웨어 엔지니어
모든 훌륭한 엔지니어처럼, 하이릴은 열정적인 학습자입니다. 그는 C#, Python, Java에 대한 지식을 갈고닦아 Iron Software의 팀원들에게 가치를 더하고 있습니다. 하이릴은 말레이시아의 Universiti Teknologi MARA에서 화학 및 공정 공학 학사 학위를 취득한 후 Iron Software 팀에 합류했습니다.
시작할 준비 되셨나요?
Nuget 다운로드 2,108,094 | 버전: 2026.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package BarCode
샘플을 실행하세요 실이 바코드로 변하는 모습을 지켜보세요.