How to Read Barcodes From System.Drawing in C
IronBarcode는 모든 운영 체제에서 System.Drawing 객체의 BARCODE를 AnyBitmap에서 IronDrawing까지 자동으로 변환하여 읽을 수 있게 함으로써, System.Drawing 지원에 대한 Microsoft Windows 전용의 한계를 해결합니다.
소개
System.Drawing 객체는 .NET에서 이미지 처리 작업에 널리 사용됩니다. 그러나 Microsoft는 macOS 및 Linux에서 System.Drawing에 대한 지원을 중단했으며, 현재는 Windows에서만 지원합니다. BARCODE 작업에는 일반적으로 그래픽, 이미지 및 글꼴이 포함되기 때문에, 이러한 변경 사항은 Windows 이외의 운영 체제에서 IronBarcode를 사용하는 개발자들에게 문제를 야기했습니다.
이 문제를 해결하기 위해 IronDrawing을 도입했습니다. Iron Software에서 개발한 이 무료 오픈소스 라이브러리는 크로스 플랫폼 지원을 간소화하고 원활한 사용자 경험을 제공합니다. NuGet에서 IronBarcode를 설치하면 IronDrawing이 프로젝트에 자동으로 포함됩니다.
BarCode 판독이 처음인 개발자분들은 기본 개념과 기본적인 사용 방법을 다루는 포괄적인 'BarCode 판독 튜토리얼'을 참고하시기 바랍니다. 다양한 이미지 형식을 다루고 계신다면, 이미지에서 BARCODE를 읽는 방법에 대한 가이드에서 추가적인 배경 정보와 예시를 확인하실 수 있습니다.
빠른 시작: 한 줄의 간단한 코드로 AnyBitmap을 사용하여 BARCODE 읽기
이 코드 조각은 IronBarcode가 System.Drawing.Bitmap을 생성하고 IronDrawing가 이를 AnyBitmap로 암시적으로 형변환하도록 하여 BARCODE를 읽는 방법을 보여줍니다. 단 한 줄의 코드만으로 모든 OS의 개발자가 빠른 결과를 얻을 수 있습니다.
최소 워크플로 (5단계)
- BARCODE를 읽기 위한 C# 라이브러리를 다음에서 다운로드하세요.
System.Drawing - *cast*
IronDrawing를 사용하여System.Drawing를 사용하여 객체를AnyBitmap - 바코드를 읽으려면
Read메서드를 사용하여 BarCode를 읽는 방법AnyBitmap객체에서 바코드를 읽으십시오 - 감지된 BarCode 값을 콘솔에 표시합니다
- 다른 기사를 통해
IronDrawing색상과 글꼴 처리에 사용되는지 알아보세요
System.Drawing 객체를 AnyBitmap로 어떻게 형변환하나요?
System.Drawing의 BARCODE를 읽으려면 객체를 AnyBitmap로 형변환해야 합니다. IronDrawing는 사용 편의성을 위해 설계되었으며, System.Drawing의 이미지 객체를 IronSoftware.Drawing라는 AnyBitmap 이미지 객체로 암시적 형변환을 지원합니다.
System.Drawing 객체 외에도, 다른 유형에서의 형 변환을 지원합니다:
System.Drawing.BitmapSystem.Drawing.ImageSkiaSharp.SKBitmapSkiaSharp.SKImageSixLabors.ImageSharp
위 객체들의 형변환에 대한 코드 예제는 여기를 참조하십시오. 다음은 System.Drawing 객체의 BARCODE 이미지를 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);
Imports IronSoftware.Drawing
Imports System.Collections.Generic
Private barcodes As New List(Of AnyBitmap)()
' Instantiate System.Drawing.Bitmap
Private bitmapFromBitmap As New System.Drawing.Bitmap("test1.jpg")
' Cast from System.Drawing.Bitmap to AnyBitmap
Private barcode1 As AnyBitmap = bitmapFromBitmap
barcodes.Add(barcode1)
' Instantiate System.Drawing.Bitmap
Dim bitmapFromFile As System.Drawing.Image = System.Drawing.Image.FromFile("test2.png")
' Cast from System.Drawing.Image to AnyBitmap
Dim barcode2 As AnyBitmap = bitmapFromFile
barcodes.Add(barcode2)
이 코드는 System.Drawing 객체와 IronBarcode 간의 IronDrawing을 통한 원활한 통합을 보여줍니다. 이러한 호환성은 QR 코드, Code 128, Code 39 등 지원되는 BARCODE 형식 가이드에 자세히 설명된 다양한 BARCODE 형식에 걸쳐 적용됩니다.
암시적 형 변환은 왜 작동할까요?
위의 코드에서 두 개의 BARCODE 이미지를 System.Drawing.Bitmap 및 System.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
}
Imports System.Drawing
' Implicit casting - clean and simple for straightforward conversions
Dim systemBitmap As New Bitmap("barcode.png")
Dim anyBitmap As AnyBitmap = systemBitmap ' Implicit cast
' Explicit casting - useful when type clarity is important
Dim systemImage As Image = Image.FromFile("qrcode.jpg")
Dim explicitBitmap As AnyBitmap = CType(systemImage, AnyBitmap) ' Explicit cast
' When working with nullable types or conditional logic
Dim nullableBitmap As Bitmap = GetBitmapFromSource()
If nullableBitmap IsNot Nothing Then
Dim result As AnyBitmap = CType(nullableBitmap, AnyBitmap) ' Explicit cast for clarity
' Process the barcode
End If
흔히 발생하는 캐스팅 오류에는 어떤 것들이 있나요?
System.Drawing를 AnyBitmap로 변환할 때 개발자는 다음과 같은 상황을 마주칠 수 있습니다:
- Null 참조 예외: 형변환 전에
System.Drawing객체가 null이 아닌지 확인하십시오 - 지원되지 않는 형식 예외: 일부 특수한 이미지 형식은 사전 변환이 필요합니다
- 메모리 문제: 대용량 이미지는 적절한 처리 방식이 필요합니다
캐스팅 문제 해결을 위해, 당사의 문제 해결 가이드에서는 BarCode 인식 시 발생하는 일반적인 문제에 대한 해결책을 제공합니다.
AnyBitmap 객체에서 BARCODE를 어떻게 읽을 수 있나요?
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);
}
}
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
' Create a list of image file paths to read barcodes from
Dim barcodeFiles As New List(Of String) From {
"test1.jpg",
"test2.png"
}
For Each barcodeFile In barcodeFiles
' Read the barcode from file path
Dim results = BarcodeReader.Read(barcodeFile)
For Each result In results
' Output the detected barcode value
Console.WriteLine(result.Value)
Next
Next
기본적인 Read 메서드 외에도, IronBarcode는 AnyBitmap 매개변수를 받는 여러 메서드를 제공합니다. 고급 사용 사례에 대해서는 단일 이미지에 포함된 여러 BarCode를 효율적으로 처리하는 방법을 보여주는 '여러 BarCode 읽기' 가이드를 참조하십시오:
// Advanced barcode reading with options
var readerOptions = new BarcodeReaderOptions
{
// Specify barcode types to search for
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Co/de128,
// 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.Co/de128,
// 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
Dim readerOptions As New BarcodeReaderOptions With {
' Specify barcode types to search for
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
' Enable machine learning for better accuracy
.UseML = True,
' Set confidence threshold
.Confidence = 0.95
}
' Read with specific options
Dim advancedResults = BarcodeReader.Read(anyBitmap, readerOptions)
여러 개의 BarCode 결과가 나올 경우 어떻게 처리해야 하나요?
위의 코드는 이전 예제를 확장한 것입니다. AnyBitmap 목록을 채운 후, 이를 순차적으로 처리하며 각 AnyBitmap 객체에 대해 Read 메서드를 호출했고, 그 결과 IronBarCode.BarcodeResults가 반환되었습니다. 그런 다음 결과를 반복 처리하여 BarCode 값을 콘솔에 출력했습니다.
여러 BarCode를 처리할 때는 더 나은 성능을 위해 병렬 처리를 활용하십시오:
// 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}");
}
Imports System.IO
Imports System.Collections.Concurrent
Imports System.Drawing
Imports System.Threading.Tasks
' Parallel processing for multiple barcode images
Dim barcodeFiles = Directory.GetFiles("barcodes/", "*.png")
Dim allResults = New ConcurrentBag(Of BarcodeResult)()
Parallel.ForEach(barcodeFiles, Sub(file)
Dim bitmap = New Bitmap(file)
Dim anyBitmap = CType(bitmap, AnyBitmap)
Dim results = BarcodeReader.Read(anyBitmap)
For Each result In results
allResults.Add(result)
Next
bitmap.Dispose() ' Clean up resources
End Sub)
' Process all results
For Each result In allResults
Console.WriteLine($"Found {result.BarcodeType}: {result.Value}")
Next
IronDrawing의 다른 어떤 기능을 사용할 수 있나요?
IronSoftware.Drawing의 기능은 이미지 변환을 넘어 확장됩니다. BarCode 및 QR 코드 스타일에 유용한 색상 및 글꼴과 같은 이미지 처리 기능을 지원합니다. IronDrawing를 활용하여 QR 코드를 맞춤 설정하고 로고를 추가하는 방법을 확인해 보세요.
IronDrawing는 BarCode 처리 기능을 보완하는 강력한 이미지 조작 기능을 제공합니다:
// 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.Co/ntrast(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.Co/ntrast(1.5); // Increase contrast
preprocessedImage = preprocessedImage.Sharpen(); // Sharpen image
// Read the preprocessed barcode
var improvedResults = BarcodeReader.Read(preprocessedImage);
Imports IronSoftware.Drawing
' Load and preprocess an image before barcode reading
Dim preprocessedImage As AnyBitmap = 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
Dim improvedResults = BarcodeReader.Read(preprocessedImage)
특정 이미지 보정이 필요한 경우, 당사의 이미지 보정 가이드에서 필터를 사용하여 BarCode 판독성을 높이는 방법을 자세히 설명하고 있습니다.
왜 IronDrawing을 System.Drawing보다 선택해야 할까요?
IronDrawing은 System.Drawing에 비해 다음과 같은 확실한 장점을 제공합니다:
- 크로스 플랫폼 지원:
System.Drawing( .NET Core/5+에서 Windows 전용)과 달리 Windows, Linux, macOS에서 원활하게 작동합니다. - 최신 아키텍처: 향상된 성능과 메모리 관리를 위해
SkiaSharp및ImageSharp기반으로 구축되었습니다. - 간소화된 API: 익숙한
System.Drawing와 유사한 인터페이스를 유지하면서 현대적인 편의 기능을 추가합니다 - 활발한 개발: 유지보수 모드에 있는
System.Drawing와 달리 정기적인 업데이트 및 개선이 이루어지고 있습니다. - 향상된 통합: Iron Software 제품과 최적의 성능을 발휘하도록 특별히 설계되었습니다
배포 관련 고려 사항, 특히 클라우드 환경에 대해서는 IronDrawing을 사용한 크로스 플랫폼 호환성에 대한 구체적인 설명이 포함된 Azure 배포 가이드 및 AWS 배포 가이드를 참조하십시오.
데스크톱 애플리케이션, 웹 서비스 또는 클라우드 네이티브 솔루션을 구축하든, IronDrawing은 BarCode 처리 코드가 모든 플랫폼에서 이식성과 효율성을 유지하도록 보장하므로, 현대적인 .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으로 형변환한 다음, 이미지에 있는 모든 바코드를 읽어옵니다.
IronBarcode가 바코드 외관 사용자화를 제공하나요?
네, IronBarcode는 바코드 외관에 대한 광범위한 사용자화 옵션을 제공하여 컬러, 크기 및 텍스트 주석을 포함해 특정 디자인 요구에 맞출 수 있습니다.
IronBarcode가 비즈니스 프로세스 효율성을 어떻게 향상시킬 수 있나요?
IronBarcode는 빠르고 정확한 바코드 생성 및 읽기를 가능하게 하여 수동 데이터 입력 오류를 줄이고, 재고 및 자산 추적을 향상시킴으로써 비즈니스 프로세스 효율성을 향상시킵니다.
IronBarcode를 프로젝트에 구현하려면 어떤 프로그래밍 기술이 필요하나요?
C# 프로그래밍의 기본 지식만 있으면 IronBarcode를 프로젝트에 구현하기에 충분합니다. IronBarcode는 개발자를 안내할 수 있는 간단한 메서드와 포괄적인 문서를 제공합니다.
IronBarcode는 소규모 프로젝트와 대규모 Enterprise 응용 프로그램 모두에 적합합니까?
IronBarcode는 확장 가능하고 다재다능하게 설계되어 소규모 프로젝트뿐만 아니라 견고한 바코드 솔루션이 필요한 대규모 Enterprise 응용 프로그램에 적합합니다.

