시스템 도면 객체에서 바코드를 읽는 방법

How to Read Barcodes From System.Drawing in C#

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

IronBarcode는 모든 운영 체제에서 System.Drawing 객체에서 바코드를 읽을 수 있도록 하여 Windows 전용 System.Drawing 지원의 Microsoft 제한을 해결하기 위해 AnyBitmap로 자동 변환합니다.

소개

.NET에서 이미지 처리 작업을 위해 널리 사용되는 System.Drawing 객체. 그러나 Microsoft는 System.Drawing에 대한 지원을 MacOSLinux에서 중단하고 이제는 Windows만 지원합니다. 이 변경은 바코드 작업이 보통 그래픽, 이미지, 폰트와 관련되어 있기 때문에 비-Windows 운영 체제에서 IronBarcode를 사용하는 개발자에게 문제를 발생시켰습니다.

이 문제를 해결하기 위해 IronDrawing을 소개했습니다. IronSoftware가 제작한 이 무료오픈 소스 라이브러리는 크로스 플랫폼 지원을 간소화하고 원활한 경험을 제공합니다. IronBarcode를 NuGet에서 설치하면 IronDrawing가 프로젝트에 자동으로 포함됩니다.

바코드 읽기에 익숙하지 않은 개발자는 기본 개념 및 기본 사용 패턴을 다루는 포괄적인 바코드 읽기 튜토리얼을 참조하세요. 다양한 이미지 형식을 사용하는 경우, 이미지에서 바코드 읽기에 대한 우리의 가이드가 추가적인 문맥과 예제를 제공합니다.

빠른 시작: 한 줄로 AnyBitmap을 사용하여 바코드 읽기

이 코드 조각은 System.Drawing.Bitmap을 생성하여 IronBarcode가 바코드를 어떻게 읽는지 보여주며, 이는 IronDrawing이 암시적으로 AnyBitmap로 캐스팅하는 것을 허용합니다. 단 한 줄만으로도 다양한 운영 체제에서 빠른 결과를 얻을 수 있습니다.

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

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

    var results = IronBarCode.BarcodeReader.Read((AnyBitmap)(new System.Drawing.Bitmap("yourImage.png")));
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

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

    arrow pointer

System.Drawing 객체를 AnyBitmap으로 어떻게 캐스팅하나요?

System.Drawing에서 바코드를 읽으려면 객체를 AnyBitmap로 캐스팅해야 합니다. IronDrawing는 사용 편의성을 위해 설계되었으며 System.Drawing에서 IronSoftware.Drawing 이미지 객체로 불리는 AnyBitmap으로 이미지 객체의 암시적 캐스팅을 지원합니다.

System.Drawing 객체 외에도 우리는 다른 유형의 캐스팅을 지원합니다:

  • System.Drawing.Bitmap
  • System.Drawing.Image
  • SkiaSharp.SKBitmap
  • SkiaSharp.SKImage
  • SixLabors.ImageSharp

위 객체를 lastPage()로 캐스팅하는 코드 예제를 참조하세요. 아래는 System.Drawing 객체에서 IronSoftware.Drawing.AnyBitmap으로 바코드 이미지를 캐스팅하는 것을 보여줍니다:

캐스팅할 수 있는 System.Drawing 유형은 무엇입니까?

:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-system-drawing-cast-to-anybitmap.cs
using IronSoftware.Drawing;
using System.Collections.Generic;

List<AnyBitmap> barcodes = new List<AnyBitmap>();

// Instantiate System.Drawing.Bitmap
System.Drawing.Bitmap bitmapFromBitmap = new System.Drawing.Bitmap("test1.jpg");

// Cast from System.Drawing.Bitmap to AnyBitmap
AnyBitmap barcode1 = bitmapFromBitmap;

barcodes.Add(barcode1);

// Instantiate System.Drawing.Bitmap
System.Drawing.Image bitmapFromFile = System.Drawing.Image.FromFile("test2.png");

// Cast from System.Drawing.Image to AnyBitmap
AnyBitmap barcode2 = bitmapFromFile;

barcodes.Add(barcode2);
$vbLabelText   $csharpLabel

이 코드는 System.Drawing 객체와 IronBarcode 간의 IronDrawing을 통한 원활한 통합을 보여줍니다. 지원되는 바코드 형식 가이드에 자세히 설명된 다양한 바코드 형식 전반에 걸쳐 호환성이 확장되며, 여기에는 QR 코드, 코드 128, 코드 39 및 기타 여러 가지가 포함됩니다.

암시적 캐스팅이 왜 작동하나요?

위의 코드에서는 두 개의 바코드 이미지를 System.Drawing.BitmapSystem.Drawing.Image로 로드했습니다. 그런 다음 이 객체들을 AnyBitmap로 암시적으로 캐스팅하여 AnyBitmap 객체에 할당한 다음, 이 객체들을 AnyBitmap 목록에 추가했습니다.

IronDrawing의 암시적 캐스팅 메커니즘은 연산자 오버로딩을 사용하여 System.Drawing 타입과 AnyBitmap 간의 투명한 변환을 제공합니다. 이 디자인 패턴은 개발자가 기존 코드를 유지하면서 플랫폼 간의 호환성을 확보할 수 있게 합니다. 변환은 해상도, 색상 깊이, 픽셀 데이터를 포함한 모든 이미지 속성을 보존하여 품질 손실이 없도록 보장합니다.

명시적 캐스팅을 사용할 때와 암시적 캐스팅을 사용할 때는 언제인가요?

암시적 캐스팅은 편리함을 제공하지만, 일부 상황에서는 명시적 캐스팅이 선호될 수 있습니다:

// Implicit casting - clean and simple for straightforward conversions
System.Drawing.Bitmap systemBitmap = new System.Drawing.Bitmap("barcode.png");
AnyBitmap anyBitmap = systemBitmap; // Implicit cast

// Explicit casting - useful when type clarity is important
System.Drawing.Image systemImage = System.Drawing.Image.FromFile("qrcode.jpg");
AnyBitmap explicitBitmap = (AnyBitmap)systemImage; // Explicit cast

// When working with nullable types or conditional logic
System.Drawing.Bitmap? nullableBitmap = GetBitmapFromSource();
if (nullableBitmap != null)
{
    AnyBitmap result = (AnyBitmap)nullableBitmap; // Explicit cast for clarity
    // Process the barcode
}
// Implicit casting - clean and simple for straightforward conversions
System.Drawing.Bitmap systemBitmap = new System.Drawing.Bitmap("barcode.png");
AnyBitmap anyBitmap = systemBitmap; // Implicit cast

// Explicit casting - useful when type clarity is important
System.Drawing.Image systemImage = System.Drawing.Image.FromFile("qrcode.jpg");
AnyBitmap explicitBitmap = (AnyBitmap)systemImage; // Explicit cast

// When working with nullable types or conditional logic
System.Drawing.Bitmap? nullableBitmap = GetBitmapFromSource();
if (nullableBitmap != null)
{
    AnyBitmap result = (AnyBitmap)nullableBitmap; // Explicit cast for clarity
    // Process the barcode
}
$vbLabelText   $csharpLabel

일반적인 캐스팅 오류는 무엇인가요?

System.DrawingAnyBitmap로 변환할 때 개발자가 직면할 수 있는 문제:

  1. 널 참조 예외: 캐스팅하기 전에 System.Drawing 객체가 널이 아닌지 확인
  2. 지원되지 않는 형식 예외: 일부 희귀한 이미지 형식은 사전 변환이 필요합니다
  3. 메모리 문제: 큰 이미지는 적절한 폐기 패턴을 사용해야 합니다

캐스팅 문제를 해결하려면, 바코드 인식 중 발생하는 일반적인 문제에 대한 해결책을 제공하는 문제 해결 가이드를 참조하세요.

AnyBitmap 객체에서 바코드를 어떻게 읽나요?

IronBarcode는 모든 메서드에서 IronSoftware.Drawing.AnyBitmap 객체를 추가 구성 없이 수락합니다. 이는 비 Windows 운영 체제에서 System.Drawing 객체를 사용할 때 개발을 단순화합니다. 다음 코드는 이를 시연합니다:

AnyBitmap 매개변수를 수락하는 메서드는 무엇입니까?

:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-system-drawing-read-anybitmap.cs
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;

// Create a list of image file paths to read barcodes from
List<string> barcodeFiles = new List<string>
{
    "test1.jpg",
    "test2.png"
};

foreach (var barcodeFile in barcodeFiles)
{
    // Read the barcode from file path
    var results = BarcodeReader.Read(barcodeFile);
    foreach (var result in results)
    {
        // Output the detected barcode value
        Console.WriteLine(result.Value);
    }
}
$vbLabelText   $csharpLabel

기본 Read 메서드 외에도, IronBarcode는 AnyBitmap 매개변수를 수용하는 여러 메서드를 제공합니다. 고급 시나리오를 위해, 다중 바코드 읽기 가이드를 참조하여 단일 이미지에서 여러 바코드를 효율적으로 처리하는 방법을 보여줍니다:

// Advanced barcode reading with options
var readerOptions = new BarcodeReaderOptions
{
    // Specify barcode types to search for
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
    // Enable machine learning for better accuracy
    UseML = true,
    // Set confidence threshold
    Confidence = 0.95
};

// Read with specific options
var advancedResults = BarcodeReader.Read(anyBitmap, readerOptions);
// Advanced barcode reading with options
var readerOptions = new BarcodeReaderOptions
{
    // Specify barcode types to search for
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
    // Enable machine learning for better accuracy
    UseML = true,
    // Set confidence threshold
    Confidence = 0.95
};

// Read with specific options
var advancedResults = BarcodeReader.Read(anyBitmap, readerOptions);
$vbLabelText   $csharpLabel

다중 바코드 결과를 어떻게 처리하나요?

위 코드는 이전 예제를 확장합니다. AnyBitmap 리스트를 채운 후, 우리는 그것을 반복하고 각 AnyBitmap 객체에 Read 메서드를 호출했습니다, 이는 IronBarCode.BarcodeResults를 반환했습니다. 그런 다음 결과를 반복하여 콘솔에 바코드 값을 출력했습니다.

다중 바코드를 처리할 때는 병렬 처리를 활용하여 성능을 향상하세요:

// Parallel processing for multiple barcode images
var barcodeFiles = Directory.GetFiles("barcodes/", "*.png");
var allResults = new ConcurrentBag<BarcodeResult>();

Parallel.ForEach(barcodeFiles, file =>
{
    var bitmap = new System.Drawing.Bitmap(file);
    var anyBitmap = (AnyBitmap)bitmap;
    var results = BarcodeReader.Read(anyBitmap);

    foreach (var result in results)
    {
        allResults.Add(result);
    }

    bitmap.Dispose(); // Clean up resources
});

// Process all results
foreach (var result in allResults)
{
    Console.WriteLine($"Found {result.BarcodeType}: {result.Value}");
}
// Parallel processing for multiple barcode images
var barcodeFiles = Directory.GetFiles("barcodes/", "*.png");
var allResults = new ConcurrentBag<BarcodeResult>();

Parallel.ForEach(barcodeFiles, file =>
{
    var bitmap = new System.Drawing.Bitmap(file);
    var anyBitmap = (AnyBitmap)bitmap;
    var results = BarcodeReader.Read(anyBitmap);

    foreach (var result in results)
    {
        allResults.Add(result);
    }

    bitmap.Dispose(); // Clean up resources
});

// Process all results
foreach (var result in allResults)
{
    Console.WriteLine($"Found {result.BarcodeType}: {result.Value}");
}
$vbLabelText   $csharpLabel

다른 IronDrawing 기능은 무엇이 있습니까?

IronSoftware.Drawing 기능은 이미지 캐스팅을 넘어 확장됩니다. 이미지 처리 측면, 특히 바코드 및 QR 코드 스타일에 유용한 색상폰트를 처리합니다. QR 코드를 커스터마이즈하고 로고를 추가하는 방법을 살펴보세요, 우리는 IronDrawing을 활용합니다.

IronDrawing은 바코드 처리와 보완되는 강력한 이미지 조작 기능을 제공합니다:

// Using IronDrawing for image preprocessing
using IronSoftware.Drawing;

// Load and preprocess an image before barcode reading
AnyBitmap preprocessedImage = AnyBitmap.FromFile("noisy-barcode.jpg");

// Apply image filters to improve barcode readability
preprocessedImage = preprocessedImage.ToGrayScale();
preprocessedImage = preprocessedImage.Contrast(1.5); // Increase contrast
preprocessedImage = preprocessedImage.Sharpen(); // Sharpen image

// Read the preprocessed barcode
var improvedResults = BarcodeReader.Read(preprocessedImage);
// Using IronDrawing for image preprocessing
using IronSoftware.Drawing;

// Load and preprocess an image before barcode reading
AnyBitmap preprocessedImage = AnyBitmap.FromFile("noisy-barcode.jpg");

// Apply image filters to improve barcode readability
preprocessedImage = preprocessedImage.ToGrayScale();
preprocessedImage = preprocessedImage.Contrast(1.5); // Increase contrast
preprocessedImage = preprocessedImage.Sharpen(); // Sharpen image

// Read the preprocessed barcode
var improvedResults = BarcodeReader.Read(preprocessedImage);
$vbLabelText   $csharpLabel

특정 이미지 수정을 요구하는 시나리오의 경우, 이미지 수정 가이드는 필터를 사용하여 바코드 읽기 성능을 향상시키는 방법을 설명합니다.

IronDrawingSystem.Drawing 대신 선택해야 하는 이유는 무엇입니까?

IronDrawingSystem.Drawing보다 매력적인 이점을 제공합니다:

  1. 크로스 플랫폼 지원: System.Drawing가 .NET Core/5+에서는 Windows 전용인 반면, Windows, Linux, macOS에서 원활하게 작동합니다
  2. 현대적 아키텍처: 성능과 메모리 관리 개선을 위해 SkiaSharpImageSharp을 기반으로 구축되었습니다
  3. 단순화된 API: 현대적인 편의 기능을 추가하면서 System.Drawing-유사한 인터페이스를 유지합니다
  4. 활발한 개발: System.Drawing 유지보수 모드와 달리 정기적으로 업데이트 및 향상됩니다
  5. 더 나은 통합: Iron Software 제품과의 최적 성능을 위해 특별히 설계되었습니다

배포 고려 사항, 특히 클라우드 환경의 경우 Azure에 배포 및 AWS에 배포에 관한 가이드를 참조하세요, 여기에는 IronDrawing을 사용한 크로스 플랫폼 호환성에 대한 특정 노트가 포함되어 있습니다.

데스크톱 애플리케이션, 웹 서비스, 또는 클라우드 네이티브 솔루션을 구축하든 상관없이, IronDrawing은 모든 플랫폼에서 귀하의 바코드 처리 코드가 이식 가능하고 효율적으로 유지되도록 보장하여 현대 .NET 개발에 이상적인 선택입니다.

자주 묻는 질문

Windows 이외의 플랫폼에서 System.Drawing 객체의 바코드를 읽으려면 어떻게 해야 합니까?

IronBarcode는 System.Drawing 객체에서 바코드를 자동으로 읽어와 IronDrawing을 통해 AnyBitmap 형식으로 변환함으로써 플랫폼에 관계없이 바코드를 읽을 수 있도록 지원합니다. 이를 통해 System.Drawing이 Windows에서만 사용 가능하다는 Microsoft의 제약을 해결하여 macOS 및 Linux 시스템에서도 바코드를 원활하게 읽을 수 있습니다.

IronDrawing이란 무엇이며 바코드 판독에 포함되는 이유는 무엇입니까?

IronDrawing은 Iron Software에서 개발한 무료 오픈 소스 라이브러리로, 다양한 플랫폼에서 그래픽 작업을 지원합니다. NuGet에서 IronBarcode를 설치하면 자동으로 포함되며, System.Drawing 객체의 바코드를 호환되는 AnyBitmap 형식으로 변환하여 모든 운영 체제에서 바코드를 읽을 수 있도록 해줍니다.

System.Drawing.Bitmap에서 바코드를 읽을 수 있도록 변환하려면 어떻게 해야 하나요?

System.Drawing.Bitmap에서 AnyBitmap으로 간단히 형변환하여 바코드를 읽을 수 있습니다. 예: `var results = BarcodeReader.Read((AnyBitmap)(new System.Drawing.Bitmap("yourImage.png")));`. IronBarcode는 IronDrawing의 암시적 형변환 기능을 통해 변환을 자동으로 처리합니다.

Linux와 MacOS에서 System.Drawing을 사용하여 바코드를 읽을 수 있습니까?

예, IronBarcode는 IronDrawing을 통해 Linux 및 MacOS에서 System.Drawing 객체의 바코드를 읽을 수 있도록 지원합니다. IronDrawing은 System.Drawing 객체를 자동으로 크로스 플랫폼 AnyBitmap 형식으로 변환합니다. 이를 통해 Microsoft의 Windows 전용 System.Drawing 지원 제한을 극복할 수 있습니다.

바코드 판독에 사용할 수 있는 System.Drawing 객체의 유형은 무엇입니까?

IronBarcode는 System.Drawing.Bitmap 및 기타 이미지 유형을 포함한 다양한 System.Drawing 객체에서 바코드를 읽는 기능을 지원합니다. 이러한 객체는 IronDrawing의 암시적 형변환 기능을 통해 자동으로 AnyBitmap으로 변환되므로 플랫폼에 관계없이 바코드 스캔 기능을 사용할 수 있습니다.

System.Drawing에서 바코드를 읽는 간단한 한 줄짜리 코드가 있을까요?

네, IronBarcode는 한 줄짜리 해결책을 제공합니다. `var results = BarcodeReader.Read((AnyBitmap)(new System.Drawing.Bitmap("yourImage.png")));` 이 한 줄 코드는 System.Drawing.Bitmap 객체를 생성하고, IronDrawing을 통해 AnyBitmap으로 형변환한 다음, 이미지에 있는 모든 바코드를 읽어옵니다.

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

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

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