using IronBarCode;using System;var myBarcode = BarcodeReader.Read(@"image_file_path.jpg"); //image file pathforeach (var item in myBarcode){Console.WriteLine(item.ToString());}
using IronBarCode;
using System;
var myBarcode = BarcodeReader.Read(@"image_file_path.jpg"); //image file path
foreach (var item in myBarcode)
{
Console.WriteLine(item.ToString());
}
ImportsIronBarCodeImportsSystemPrivate myBarcode = BarcodeReader.Read("image_file_path.jpg") 'image file pathFor Each item In myBarcodeConsole.WriteLine(item.ToString())Next item
Imports IronBarCode
Imports System
Private myBarcode = BarcodeReader.Read("image_file_path.jpg") 'image file path
For Each item In myBarcode
Console.WriteLine(item.ToString())
Next item
樣本測試QR碼樣本測試條碼想知道樣本中的條碼值是多少?試試程式碼片段!
要使用IronBarcode,您首先需要通過Microsoft Visual Studio NuGet套件管理器將IronBarcode程式庫安裝到您的專案中,如下圖所示。 這將允許您存取IronBarcode的BarcodeReader.Read()方法以直接讀取條碼圖片。
// Example of setting CropAreavar cropArea = new IronSoftware.Drawing.Rectangle(x: 100, y: 100, width: 300, height: 300);var options = new BarcodeReaderOptions(){CropArea = cropArea};
// Example of setting CropArea
var cropArea = new IronSoftware.Drawing.Rectangle(x: 100, y: 100, width: 300, height: 300);
var options = new BarcodeReaderOptions()
{
CropArea = cropArea
};
ImportsIronSoftware.Drawing' Example of setting CropAreaDim cropArea As New Rectangle(x:=100, y:=100, width:=300, height:=300)Dim options As New BarcodeReaderOptions() With { .CropArea = cropArea}
Imports IronSoftware.Drawing
' Example of setting CropArea
Dim cropArea As New Rectangle(x:=100, y:=100, width:=300, height:=300)
Dim options As New BarcodeReaderOptions() With {
.CropArea = cropArea
}
// Example: Expect only QR codes and Code128var options = new BarcodeReaderOptions(){ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128};
// Example: Expect only QR codes and Code128
var options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128
};
' Example: Expect only QR codes and Code128Dim options As New BarcodeReaderOptions() With { .ExpectBarcodeTypes = BarcodeEncoding.QRCodeOrBarcodeEncoding.Code128}
' Example: Expect only QR codes and Code128
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128
}
using IronBarCode;using IronSoftware.Drawing;using System;using System.Linq;// Create custom reader optionsvar options = new BarcodeReaderOptions(){ // Specify expected barcode types for better performanceExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128 | BarcodeEncoding.Code39, // Define specific area to scan (x, y, width, height in pixels)CropArea = new Rectangle(100, 100, 500, 400), // Set reading speed to balance accuracy and performanceSpeed = ReadingSpeed.Balanced, // Enable multithreading for better performanceMultithreaded = true,MaxParallelThreads = 4, // Remove false positives for accuracyRemoveFalsePositive = true, // Minimum scan lines that must agree for a valid result (default 2)MinScanLines = 1, // Enable Code39 extended mode if neededUseCode39ExtendedMode = true, // Set scan modeScanMode = BarcodeScanMode.Auto, // Add image filters for better recognitionImageFilters = new ImageFilterCollection() { new SharpenFilter(), new InvertFilter(), new ContrastFilter() }};// Read barcodes with custom optionsvar results = BarcodeReader.Read(@"C:\path\to\your\barcode-image.png", options);// Process resultsif (results.Any()){ foreach (var barcode in results) {Console.WriteLine($"Barcode Type: {barcode.BarcodeType}");Console.WriteLine($"Value: {barcode.Value}");Console.WriteLine($"Position: {string.Join(", ", barcode.Points.Select(p => $"({p.X}, {p.Y})"))}");Console.WriteLine("---"); }}else{Console.WriteLine("No barcodes found in the image.");}
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Linq;
// Create custom reader options
var options = new BarcodeReaderOptions()
{
// Specify expected barcode types for better performance
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128 | BarcodeEncoding.Code39,
// Define specific area to scan (x, y, width, height in pixels)
CropArea = new Rectangle(100, 100, 500, 400),
// Set reading speed to balance accuracy and performance
Speed = ReadingSpeed.Balanced,
// Enable multithreading for better performance
Multithreaded = true,
MaxParallelThreads = 4,
// Remove false positives for accuracy
RemoveFalsePositive = true,
// Minimum scan lines that must agree for a valid result (default 2)
MinScanLines = 1,
// Enable Code39 extended mode if needed
UseCode39ExtendedMode = true,
// Set scan mode
ScanMode = BarcodeScanMode.Auto,
// Add image filters for better recognition
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter()
}
};
// Read barcodes with custom options
var results = BarcodeReader.Read(@"C:\path\to\your\barcode-image.png", options);
// Process results
if (results.Any())
{
foreach (var barcode in results)
{
Console.WriteLine($"Barcode Type: {barcode.BarcodeType}");
Console.WriteLine($"Value: {barcode.Value}");
Console.WriteLine($"Position: {string.Join(", ", barcode.Points.Select(p => $"({p.X}, {p.Y})"))}");
Console.WriteLine("---");
}
}
else
{
Console.WriteLine("No barcodes found in the image.");
}
What are the benefits of using multithreading in IronBarcode?
Multithreading in IronBarcode allows multiple barcodes to be processed simultaneously, improving the speed and efficiency of barcode reading, especially in batch processing tasks.
How do image filters improve barcode recognition in IronBarcode?
Image filters in IronBarcode enhance preprocessing by improving the clarity of barcode images. Filters like the `SharpenFilter` and `ContrastFilter` help optimize image quality for better recognition.
What is the `MinScanLines` property used for in IronBarcode?
The `MinScanLines` property sets the minimum number of scan lines that must agree on a barcode result for it to be considered valid, reducing false positives while ensuring detection accuracy.
How do I handle multiple barcode types with IronBarcode?
In IronBarcode, you can specify which barcode types to read by setting the `ExpectBarcodeTypes` property in `BarcodeReaderOptions`, which improves performance by focusing on specific barcode types.