Jak obsługiwac sprawdzanie null w operacjach z kodami kreskowymi w C#
IronBarcode zwraca wyniki skanowania jako kolekcję BarcodeResults w C# przez BarcodeReader.Read. Ta metoda zwraca null, jeśli obraz wejściowy nie jest rozpoznawany, lub pustą kolekcję, jeśli nie wykryto kodów kreskowych. BarcodeWriter.CreateBarcode zgłasza wyjątek, jeśli wejście jest null, puste lub w nieprawidłowym formacie.
Zrodla skanowania w rzeczywistych sytuacjach, takie jak sygnaly z kamer, przesyłanie dokumentów i skanery magazynowe, mogą nie zawsze dostarczać czytelny kod kreskowy. Dostęp do właściwości wyników lub iterowanie przez kolekcję bez sprawdzenia null lub pustych wartości może spowodować NullReferenceException w czasie wykonania. Przekazywanie niepoprawnych łańcuchów do API zapisu może skutkować ArgumentException. użycie strażników w operacjach odczytu i zapisu pomaga zapobiegać tym wyjątkom w produkcji.
Ten przewodnik wyjaśnia, jak obsłużyć puste i null wyniki w operacjach odczytu i zapisu IronBarcode, używając strażników, filtrowania według pewności i wzorca walidatora wielokrotnego użytku.
Podstawy: Obsluguj puste wyniki w operacjach z kodami kreskowymi
Użyj wzorca ochronnego IronBarcode, aby bezpiecznie sprawdzić kolekcję BarcodeResults przed dostępem do jakichkolwiek właściwości wyników. Zacznij od razu od tego minimalnego odczytu i sprawdzenia:
-
1Zainstaluj IronBarcode z NuGet Package Manager
-
2Skopiuj i uruchom ten fragment kodu.
using IronBarCode; using System; using System.Linq; BarcodeResults results = BarcodeReader.Read("label.png"); // Guard: null or empty if (results is null || results.Count == 0) { Console.WriteLine("No barcodes detected."); return; } Console.WriteLine(results.First().Value);Imports IronBarCode Imports System Imports System.Linq Dim results As BarcodeResults = BarcodeReader.Read("label.png") ' Guard: null or empty If results Is Nothing OrElse results.Count = 0 Then Console.WriteLine("No barcodes detected.") Return End If Console.WriteLine(results.First().Value)Imports IronBarCode Imports System Imports System.Linq Dim results As BarcodeResults = BarcodeReader.Read("label.png") ' Guard: null or empty If results Is Nothing OrElse results.Count = 0 Then Console.WriteLine("No barcodes detected.") Return End If Console.WriteLine(results.First().Value) -
3Wdrożenie do testowania w środowisku produkcyjnym
Rozpocznij korzystanie z IronBarcode w swoim projekcie już dziś z darmową wersją próbną
Jak obsługiwac sprawdzanie null w operacjach z kodami kreskowymi z IronBarcode
- Pobierz bibliotekę IronBarcode z NuGet
- Wywołaj
BarcodeReader.Readi złap zwracanyBarcodeResults - Sprawdź pod kątem null przed uzyskaniem dostępu do jakiegokolwiek wyniku
- Zweryfikuj poszczegółne właściwości
BarcodeResultprzed użyciem dalszym - Ustaw
ConfidenceThresholdnaBarcodeReaderOptionsw celu filtrowania słabej jakości odczytów na poziomie skanowania
Jak obsługiwac puste wyniki z kodami kreskowymi?
Istnieją dwa tryby niepowodzenia: BarcodeResults jest null, jeśli wejście nie jest poprawnym obrazem, oraz puste, jeśli obraz nie zawiera kodów kreskowych. Dostęp do First, Value, lub iterowanie bez weryfikacji obu warunków spowoduje wyjątek w czasie wykonania.
Sprawdź oba warunki przed rozpoczęciem pętli przetwarzania:
Dane wejściowe
Code128 etykieta wysyłki kodu kreskowego (ścieżka sukcesu) i pusty obraz nie zawierający kodu kreskowego (ścieżka niepowodzenia).

shipping-label.png (ścieżka success)

blank-image.png (ścieżka failure, brak kodu kreskowego)
using IronBarCode;
// BarcodeReader.Read() returns a BarcodeResults collection, not a single result
BarcodeResults results = BarcodeReader.Read("shipping-label.png");
// Null check: image was not recognized as a valid image source
// Empty check: image was valid but contained no detectable barcodes
if (results is null || results.Count == 0)
{
// Log, return a default, or throw a domain-specific exception
Console.WriteLine("No barcodes found in the input image.");
return;
}
// Collection is safe to iterate; each BarcodeResult holds one decoded barcode
foreach (BarcodeResult result in results)
{
// Guard individual result properties; partial scans or severely
// damaged barcodes can produce results where .Value is empty or whitespace
if (string.IsNullOrWhiteSpace(result.Value))
{
Console.WriteLine($"Empty value detected for {result.BarcodeType}");
continue;
}
// BarcodeType identifies the symbology (Code128, QRCode, EAN8, etc.)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}");
}using IronBarCode;
// BarcodeReader.Read() returns a BarcodeResults collection, not a single result
BarcodeResults results = BarcodeReader.Read("shipping-label.png");
// Null check: image was not recognized as a valid image source
// Empty check: image was valid but contained no detectable barcodes
if (results is null || results.Count == 0)
{
// Log, return a default, or throw a domain-specific exception
Console.WriteLine("No barcodes found in the input image.");
return;
}
// Collection is safe to iterate; each BarcodeResult holds one decoded barcode
foreach (BarcodeResult result in results)
{
// Guard individual result properties; partial scans or severely
// damaged barcodes can produce results where .Value is empty or whitespace
if (string.IsNullOrWhiteSpace(result.Value))
{
Console.WriteLine($"Empty value detected for {result.BarcodeType}");
continue;
}
// BarcodeType identifies the symbology (Code128, QRCode, EAN8, etc.)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}");
}Imports IronBarCode
' BarcodeReader.Read() returns a BarcodeResults collection, not a single result
Dim results As BarcodeResults = BarcodeReader.Read("shipping-label.png")
' Null check: image was not recognized as a valid image source
' Empty check: image was valid but contained no detectable barcodes
If results Is Nothing OrElse results.Count = 0 Then
' Log, return a default, or throw a domain-specific exception
Console.WriteLine("No barcodes found in the input image.")
Return
End If
' Collection is safe to iterate; each BarcodeResult holds one decoded barcode
For Each result As BarcodeResult In results
' Guard individual result properties; partial scans or severely
' damaged barcodes can produce results where .Value is empty or whitespace
If String.IsNullOrWhiteSpace(result.Value) Then
Console.WriteLine($"Empty value detected for {result.BarcodeType}")
Continue For
End If
' BarcodeType identifies the symbology (Code128, QRCode, EAN8, etc.)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}")
NextImports IronBarCode
' BarcodeReader.Read() returns a BarcodeResults collection, not a single result
Dim results As BarcodeResults = BarcodeReader.Read("shipping-label.png")
' Null check: image was not recognized as a valid image source
' Empty check: image was valid but contained no detectable barcodes
If results Is Nothing OrElse results.Count = 0 Then
' Log, return a default, or throw a domain-specific exception
Console.WriteLine("No barcodes found in the input image.")
Return
End If
' Collection is safe to iterate; each BarcodeResult holds one decoded barcode
For Each result As BarcodeResult In results
' Guard individual result properties; partial scans or severely
' damaged barcodes can produce results where .Value is empty or whitespace
If String.IsNullOrWhiteSpace(result.Value) Then
Console.WriteLine($"Empty value detected for {result.BarcodeType}")
Continue For
End If
' BarcodeType identifies the symbology (Code128, QRCode, EAN8, etc.)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}")
NextKażdy BarcodeResult zapewnia właściwości string Value i Text, zwracające zdekodowaną zawartość kodu kreskowego. Znacznie uszkodzone kody kreskowe lub częściowe skany mogą generować puste lub białe wartości. Użyj string.IsNullOrWhiteSpace na każdym wyniku, aby zapobiec przedostawaniu się pustych wartości do systemów downstream.
BarcodeReaderOptions ma również właściwość ConfidenceThreshold (0,0 do 1,0), która odrzuca niskiej jakości odczyty zanim trafią do kolekcji wyników:
using IronBarCode;
// ConfidenceThreshold filters low-quality reads before they enter the
// BarcodeResults collection. Reads below the threshold are discarded
// during scanning, not after, so no post-filtering of the collection is needed.
var options = new BarcodeReaderOptions
{
ConfidenceThreshold = 0.7 // range 0.0 to 1.0; lower values accept weaker signals
};
BarcodeResults results = BarcodeReader.Read("shipping-label.png", options);
// Still check for null and empty even with a threshold applied;
// an image with no barcodes returns an empty collection, not null
if (results is null || results.Count == 0)
{
Console.WriteLine("No barcodes met the confidence threshold.");
return;
}
foreach (var result in results)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}");using IronBarCode;
// ConfidenceThreshold filters low-quality reads before they enter the
// BarcodeResults collection. Reads below the threshold are discarded
// during scanning, not after, so no post-filtering of the collection is needed.
var options = new BarcodeReaderOptions
{
ConfidenceThreshold = 0.7 // range 0.0 to 1.0; lower values accept weaker signals
};
BarcodeResults results = BarcodeReader.Read("shipping-label.png", options);
// Still check for null and empty even with a threshold applied;
// an image with no barcodes returns an empty collection, not null
if (results is null || results.Count == 0)
{
Console.WriteLine("No barcodes met the confidence threshold.");
return;
}
foreach (var result in results)
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}");Imports IronBarCode
' ConfidenceThreshold filters low-quality reads before they enter the
' BarcodeResults collection. Reads below the threshold are discarded
' during scanning, not after, so no post-filtering of the collection is needed.
Dim options As New BarcodeReaderOptions With {
.ConfidenceThreshold = 0.7 ' range 0.0 to 1.0; lower values accept weaker signals
}
Dim results As BarcodeResults = BarcodeReader.Read("shipping-label.png", options)
' Still check for null and empty even with a threshold applied;
' an image with no barcodes returns an empty collection, not null
If results Is Nothing OrElse results.Count = 0 Then
Console.WriteLine("No barcodes met the confidence threshold.")
Return
End If
For Each result In results
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}")
NextImports IronBarCode
' ConfidenceThreshold filters low-quality reads before they enter the
' BarcodeResults collection. Reads below the threshold are discarded
' during scanning, not after, so no post-filtering of the collection is needed.
Dim options As New BarcodeReaderOptions With {
.ConfidenceThreshold = 0.7 ' range 0.0 to 1.0; lower values accept weaker signals
}
Dim results As BarcodeResults = BarcodeReader.Read("shipping-label.png", options)
' Still check for null and empty even with a threshold applied;
' an image with no barcodes returns an empty collection, not null
If results Is Nothing OrElse results.Count = 0 Then
Console.WriteLine("No barcodes met the confidence threshold.")
Return
End If
For Each result In results
Console.WriteLine($"Type: {result.BarcodeType}, Value: {result.Value}")
NextJak zastosować wzorce bezpieczne dla null w zapisie kodów kreskowych?
BarcodeWriter.CreateBarcode przyjmuje wartość łańcuchową i BarcodeWriterEncoding lub BarcodeEncoding enum. Przekazanie null lub pustego ciągu znaków natychmiast rzuca wyjątek. Ograniczenia formatu również obowiązują: EAN-8 akceptuje od 7 do 8 cyfr, UPC-A akceptuje od 11 do 12, a Code 128 ma limit znaków. Walidacja wejścia przed wywołaniem utrzymuje te wyjątki poza krokiem kodowania:
using IronBarCode;
// Input may arrive from user input, a database, or an API response
string inputValue = GetValueFromUserOrDatabase(); // Could be null
// Guard: null, empty, or whitespace input cannot produce a valid barcode
if (string.IsNullOrWhiteSpace(inputValue))
{
Console.WriteLine("Cannot generate barcode: input value is null or empty.");
return;
}
// Guard: format-specific constraints must be satisfied before encoding
// EAN-8 accepts exactly 7 or 8 numeric digits (the 8th is the check digit)
BarcodeWriterEncoding encoding = BarcodeWriterEncoding.EAN8;
if (encoding == BarcodeWriterEncoding.EAN8 && !System.Text.RegularExpressions.Regex.IsMatch(inputValue, @"^\d{7,8}$"))
{
Console.WriteLine("EAN-8 requires exactly 7 or 8 numeric digits.");
return;
}
// Input is validated; CreateBarcode will not throw for null or format mismatch
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(inputValue, encoding);
barcode.SaveAsPng("output-barcode.png");using IronBarCode;
// Input may arrive from user input, a database, or an API response
string inputValue = GetValueFromUserOrDatabase(); // Could be null
// Guard: null, empty, or whitespace input cannot produce a valid barcode
if (string.IsNullOrWhiteSpace(inputValue))
{
Console.WriteLine("Cannot generate barcode: input value is null or empty.");
return;
}
// Guard: format-specific constraints must be satisfied before encoding
// EAN-8 accepts exactly 7 or 8 numeric digits (the 8th is the check digit)
BarcodeWriterEncoding encoding = BarcodeWriterEncoding.EAN8;
if (encoding == BarcodeWriterEncoding.EAN8 && !System.Text.RegularExpressions.Regex.IsMatch(inputValue, @"^\d{7,8}$"))
{
Console.WriteLine("EAN-8 requires exactly 7 or 8 numeric digits.");
return;
}
// Input is validated; CreateBarcode will not throw for null or format mismatch
GeneratedBarcode barcode = BarcodeWriter.CreateBarcode(inputValue, encoding);
barcode.SaveAsPng("output-barcode.png");Imports IronBarCode
' Input may arrive from user input, a database, or an API response
Dim inputValue As String = GetValueFromUserOrDatabase() ' Could be Nothing
' Guard: null, empty, or whitespace input cannot produce a valid barcode
If String.IsNullOrWhiteSpace(inputValue) Then
Console.WriteLine("Cannot generate barcode: input value is null or empty.")
Return
End If
' Guard: format-specific constraints must be satisfied before encoding
' EAN-8 accepts exactly 7 or 8 numeric digits (the 8th is the check digit)
Dim encoding As BarcodeWriterEncoding = BarcodeWriterEncoding.EAN8
If encoding = BarcodeWriterEncoding.EAN8 AndAlso Not System.Text.RegularExpressions.Regex.IsMatch(inputValue, "^\d{7,8}$") Then
Console.WriteLine("EAN-8 requires exactly 7 or 8 numeric digits.")
Return
End If
' Input is validated; CreateBarcode will not throw for null or format mismatch
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(inputValue, encoding)
barcode.SaveAsPng("output-barcode.png")Imports IronBarCode
' Input may arrive from user input, a database, or an API response
Dim inputValue As String = GetValueFromUserOrDatabase() ' Could be Nothing
' Guard: null, empty, or whitespace input cannot produce a valid barcode
If String.IsNullOrWhiteSpace(inputValue) Then
Console.WriteLine("Cannot generate barcode: input value is null or empty.")
Return
End If
' Guard: format-specific constraints must be satisfied before encoding
' EAN-8 accepts exactly 7 or 8 numeric digits (the 8th is the check digit)
Dim encoding As BarcodeWriterEncoding = BarcodeWriterEncoding.EAN8
If encoding = BarcodeWriterEncoding.EAN8 AndAlso Not System.Text.RegularExpressions.Regex.IsMatch(inputValue, "^\d{7,8}$") Then
Console.WriteLine("EAN-8 requires exactly 7 or 8 numeric digits.")
Return
End If
' Input is validated; CreateBarcode will not throw for null or format mismatch
Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(inputValue, encoding)
barcode.SaveAsPng("output-barcode.png")Wynik
Prawidłowe 7-cyfrowe wejście (1234567) tworzy skanowalny EAN-8 kod kreskowy. Wejścia null, puste lub nienumeryczne są wychwytywane przez strażników i nigdy nie docierają do kroku kodowania.

API pisania także wykonuje swoją własną, wewnętrzną walidację: sprawdza sumy kontrolne, weryfikuje ograniczenia długości i odrzuca nieprawidłowe znaki dla wybranego kodowania. Powyższe strażnicy łapią problemy wcześniej, dając dzwoniącemu kontrolę nad komunikatem o błędzie i ścieżką odzyskiwania. Aby uzyskać pełną listę obsługiwanych kodowań i ich ograniczenia, zobacz instrukcję tworzenia kodu kreskowego i przewodnik tworzenia kodu kreskowego z danych.
Jak zweryfikowac wyniki przed przetwarzaniem downstream?
Gdy dane kodu kreskowego są przekazywane do innego systemu (zapis bazy danych, wywołanie API, drukarka etykiet), warto skonsolidowac liczbę wyników, integralność wartości i sprawdzenie typu w jedną metodę do ponownego użycia przed przekazaniem danych dalej:
Dane wejściowe
Code128 zeskanowany kod kreskowy magazynu używany jako cel odczytu dla walidatora.

using IronBarCode;
using System.Collections.Generic;
using System.Linq;
// Reusable validation helper — consolidates null, empty, value, and
// expected-format checks into a single method. Returns an empty list
// (never null) so callers do not need to null-check the return value.
public static class BarcodeValidator
{
public static List<BarcodeResult> GetValidResults(
string imagePath,
BarcodeEncoding? expectedType = null,
double confidenceThreshold = 0.7)
{
// Apply confidence threshold at scan level via BarcodeReaderOptions
var options = new BarcodeReaderOptions
{
ConfidenceThreshold = confidenceThreshold
};
BarcodeResults results = BarcodeReader.Read(imagePath, options);
// Return empty list instead of null so callers never need to null-check the return value
if (results is null || results.Count == 0)
return new List<BarcodeResult>();
return results
.Where(r => !string.IsNullOrWhiteSpace(r.Value)) // skip results with empty decoded data
.Where(r => expectedType == null || r.BarcodeType == expectedType) // null accepts any symbology
.ToList();
}
}
// Usage: pass the image path and the symbology you expect
var validated = BarcodeValidator.GetValidResults(
"warehouse-scan.png",
expectedType: BarcodeEncoding.Code128,
confidenceThreshold: 0.7);
if (validated.Count == 0)
{
// No valid results; log the failure and skip downstream processing
return;
}
// All results have passed null, empty, type, and confidence checks
foreach (var barcode in validated)
{
SendToInventorySystem(barcode.Value, barcode.BarcodeType.ToString()); // placeholder for your downstream call
}using IronBarCode;
using System.Collections.Generic;
using System.Linq;
// Reusable validation helper — consolidates null, empty, value, and
// expected-format checks into a single method. Returns an empty list
// (never null) so callers do not need to null-check the return value.
public static class BarcodeValidator
{
public static List<BarcodeResult> GetValidResults(
string imagePath,
BarcodeEncoding? expectedType = null,
double confidenceThreshold = 0.7)
{
// Apply confidence threshold at scan level via BarcodeReaderOptions
var options = new BarcodeReaderOptions
{
ConfidenceThreshold = confidenceThreshold
};
BarcodeResults results = BarcodeReader.Read(imagePath, options);
// Return empty list instead of null so callers never need to null-check the return value
if (results is null || results.Count == 0)
return new List<BarcodeResult>();
return results
.Where(r => !string.IsNullOrWhiteSpace(r.Value)) // skip results with empty decoded data
.Where(r => expectedType == null || r.BarcodeType == expectedType) // null accepts any symbology
.ToList();
}
}
// Usage: pass the image path and the symbology you expect
var validated = BarcodeValidator.GetValidResults(
"warehouse-scan.png",
expectedType: BarcodeEncoding.Code128,
confidenceThreshold: 0.7);
if (validated.Count == 0)
{
// No valid results; log the failure and skip downstream processing
return;
}
// All results have passed null, empty, type, and confidence checks
foreach (var barcode in validated)
{
SendToInventorySystem(barcode.Value, barcode.BarcodeType.ToString()); // placeholder for your downstream call
}Imports IronBarCode
Imports System.Collections.Generic
Imports System.Linq
' Reusable validation helper — consolidates null, empty, value, and
' expected-format checks into a single method. Returns an empty list
' (never null) so callers do not need to null-check the return value.
Public Module BarcodeValidator
Public Function GetValidResults(
imagePath As String,
Optional expectedType As BarcodeEncoding? = Nothing,
Optional confidenceThreshold As Double = 0.7) As List(Of BarcodeResult)
' Apply confidence threshold at scan level via BarcodeReaderOptions
Dim options As New BarcodeReaderOptions With {
.ConfidenceThreshold = confidenceThreshold
}
Dim results As BarcodeResults = BarcodeReader.Read(imagePath, options)
' Return empty list instead of null so callers never need to null-check the return value
If results Is Nothing OrElse results.Count = 0 Then
Return New List(Of BarcodeResult)()
End If
Return results _
.Where(Function(r) Not String.IsNullOrWhiteSpace(r.Value)) _ ' skip results with empty decoded data
.Where(Function(r) expectedType Is Nothing OrElse r.BarcodeType = expectedType) _ ' null accepts any symbology
.ToList()
End Function
End Module
' Usage: pass the image path and the symbology you expect
Dim validated = BarcodeValidator.GetValidResults(
"warehouse-scan.png",
expectedType:=BarcodeEncoding.Code128,
confidenceThreshold:=0.7)
If validated.Count = 0 Then
' No valid results; log the failure and skip downstream processing
Return
End If
' All results have passed null, empty, type, and confidence checks
For Each barcode In validated
SendToInventorySystem(barcode.Value, barcode.BarcodeType.ToString()) ' placeholder for your downstream call
Next barcodeImports IronBarCode
Imports System.Collections.Generic
Imports System.Linq
' Reusable validation helper — consolidates null, empty, value, and
' expected-format checks into a single method. Returns an empty list
' (never null) so callers do not need to null-check the return value.
Public Module BarcodeValidator
Public Function GetValidResults(
imagePath As String,
Optional expectedType As BarcodeEncoding? = Nothing,
Optional confidenceThreshold As Double = 0.7) As List(Of BarcodeResult)
' Apply confidence threshold at scan level via BarcodeReaderOptions
Dim options As New BarcodeReaderOptions With {
.ConfidenceThreshold = confidenceThreshold
}
Dim results As BarcodeResults = BarcodeReader.Read(imagePath, options)
' Return empty list instead of null so callers never need to null-check the return value
If results Is Nothing OrElse results.Count = 0 Then
Return New List(Of BarcodeResult)()
End If
Return results _
.Where(Function(r) Not String.IsNullOrWhiteSpace(r.Value)) _ ' skip results with empty decoded data
.Where(Function(r) expectedType Is Nothing OrElse r.BarcodeType = expectedType) _ ' null accepts any symbology
.ToList()
End Function
End Module
' Usage: pass the image path and the symbology you expect
Dim validated = BarcodeValidator.GetValidResults(
"warehouse-scan.png",
expectedType:=BarcodeEncoding.Code128,
confidenceThreshold:=0.7)
If validated.Count = 0 Then
' No valid results; log the failure and skip downstream processing
Return
End If
' All results have passed null, empty, type, and confidence checks
For Each barcode In validated
SendToInventorySystem(barcode.Value, barcode.BarcodeType.ToString()) ' placeholder for your downstream call
Next barcodeMetoda zwraca pustą listę zamiast null, więc dzwoniący nie musi sprawdzać null dla wartości zwracanej. Opcjonalny parametr expectedType filtruje według symboliki, co zapobiega otrzymywaniu nieoczekiwanych formatów przez system downstream, gdy skan zbiera zarówno kod QR, jak i Code 128 z tej samej grafiki.
Dla odczytu zbiorczego przez wiele plików, zastosuj ten sam wzorzec dla każdego pliku i agreguj wyniki. Opcja ExpectBarcodeTypes na BarcodeReaderOptions zawęża skan do oczekiwanych symbolik na początku, aby mniej niechcianych wyników docierało do walidatora.
Więcej informacji
- Tutorial odczytu kodów kreskowych: konfiguracja skanowania i opcje odczytu.
- Przewodnik formatów danych wyjściowych: wszystkie właściwości
BarcodeResulti ich typy. - Tworzenie kodu kreskowego z danych: ograniczenia kodowania dla każdej symboliki.
- Dokumentacja API BarcodeReaderOptions: Kompleksowa dokumentacja konfiguracji.
- Changelog IronBarcode: Naprawy i dodatki do funkcji dla określonych wersji.
Zobacz opcje licencjonowania kiedy potok jest gotowy do produkcji.
Najczęściej zadawane pytania
Co to jest BarcodeResults w IronBarcode i jak wpływa na sprawdzanie wartości null?
BarcodeResults to kolekcja zwracana przez metode BarcodeReader.Read w IronBarcode. Bedzie to wartosc null, jesli obraz wejsciowy jest niepoprawny, i pusta, jesli nie zostana wykryte kody kreskowe, co wymaga odpowiedniego sprawdzania wartosci null, aby uniknąc wyjatkow w czasie wykonania.
Jak zabezpieczenia punktów kontroli zapobiegają wyjątkom w operacjach IronBarcode?
Zabezpieczenia punktów kontroli są stosowane w operacjach odczytu i zapisu do sprawdzania wartości null lub niepoprawnych danych wejściowych przed kontynuacją pracy, zapobiegając wyjątkom takim jak NullReferenceException i ArgumentException w produkcji.
Co się stanie, jeśli przekażesz wartość null lub pusty ciąg do BarcodeWriter.CreateBarcode?
Przekazanie wartosci null lub pustego ciagu do BarcodeWriter.CreateBarcode natychmiast wywoluje wyjatek. Walidacja danych wejsciowych przed wywolaniem zapewnia unikanie tych wyjatkow, utrzymując stabilny proces kodowania.
Jak ConfidenceThreshold wplywa na BarcodeReader w IronBarcode?
ConfidenceThreshold to właściwość w BarcodeReaderOptions, która odrzuca odczyty niskiej jakości podczas skanowania. Odczyty poniżej tego progu są odrzucane, aby nie trafiły do kolekcji wyników, poprawiając jakość skanowania.
Czy IronBarcode potrafi obsłużyć wiele typów kodów kreskowych w jednym skanie?
Tak, IronBarcode moze obsluzyc wiele typow kodow w jednym skanowaniu. Uzycie BarcodeReaderOptions z ustawieniami takimi jak ExpectBarcodeTypes pozwala skupic odczyty na konkretnych symbologiach, skutecznie zarzadzając obrazami o mieszanej tresci.
Dlaczego ważne jest, aby walidować BarcodeResults przed przetwarzaniem w dolnym strumieniu?
Walidacja BarcodeResults w celu zapewnienia liczby wynikow, integralnosci wartosci i spójnosci typów zapobiega wplywowi niepoprawnych danych na zapisy do bazy danych, wywolania API i inne interakcje systemowe.
Jaki jest wpływ braku sprawdzania rezultatow pod katem null w operacjach IronBarcode?
Brak sprawdzania rezultatów pod kątem null może prowadzić do NullReferenceException podczas operacji skanowania, ponieważ dostęp do właściwości nieistniejącego rezultatu kodu kreskowego zakończy się niepowodzeniem.
Jak działa wzorzec walidatora wielokrotnego użytku IronBarcode?
Wzorzec wielokrotnego uzytku IronBarcode konsoliduje sprawdzanie wartosci null, sprawdzanie pustych wartosci, integralność wartosci oraz walidację oczekiwanego formatu w jednej metodzie, upraszczajac proces walidacji przed wykorzystaniem wynikow w dolnym strumieniu.
Jakie ograniczenia obsługuje BarcodeWriterEncoding podczas tworzenia kodu kreskowego?
BarcodeWriterEncoding nakłada ograniczenia, takie jak długość ciągu i prawidłowość znaków w oparciu o typ kodu kreskowego. Na przykład, EAN-8 musi mieć 7 lub 8 cyfr. Poprawnie sformatowane wejście unika błędów podczas kodowania.
Jak IronBarcode zapewnia jakość zeskanowanych kodow kreskowych?
IronBarcode uzywa wlasciwosci takich jak ConfidenceThreshold w BarcodeReaderOptions, aby zapewnic, ze tylko kody kreskowe najwyzszej jakości zostaną uwzględnione w wynikach. Ten filtr przed skanowaniem oznacza, ze odczyty niskiej jakości sa odrzucane przed dalszym przetwarzaniem.
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.