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
样品测试二维码样品测试条形码想知道样品中的条形码值是什么吗?试试这段代码片段吧!
要使用 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.