如何定义条码作物区域以加快读取速度
IronBarcode 最重要的功能之一是用户可以指定裁剪区域。 该功能的目的是通过使用 "IronSoftware.Drawing.Rectangle "对象,使 IronBarcode 只读取图像中裁剪区域指定的特定条形码或区域。使用该功能不仅可以减少读取错误,还可以提高读取性能。
如何定义条码作物区域以加快读取速度
- 下载用于读取条形码的 C# 库
- 查找图像中的裁剪区域坐标和大小
- 根据坐标创建裁剪区域
- 使用
读取
检测和读取条形码的方法 - 将裁剪区域对象传递给方法
开始在您的项目中使用IronPDF,并立即获取免费试用。
查看 IronBarcode 上 Nuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。
Install-Package BarCode
考虑安装 IronBarcode DLL 直接。下载并手动安装到您的项目或GAC表单中: IronBarCode.zip
手动安装到你的项目中
下载DLL在图像中查找裁剪区域的坐标和大小
用户可以通过多种方法查找图像中某一点的坐标。其中一种方法是使用电脑中的 "画图 "程序加载图像。要获取裁剪区域的第一个坐标,请将光标移至首选的第一个点,即 "矩形 "的左上角,然后获取屏幕左下角应用程序给出的 x、y 坐标。然后,找到第二个点,即 "矩形 "的右下角。请参考下图,以便更清楚地理解。
设置作物区域参照
然后,坐标值就可以用作 Rectangle
对象的属性。对象的宽可定义为 x2 - x1,而高可定义为 y2 - y1。
:path=/static-assets/barcode/content-code-examples/how-to/set-crop-region-instantiate-CropRegion.cs
using IronBarCode;
int x1 = 62;
int y1 = 29;
int x2 = 345;
int y2 = 522;
IronSoftware.Drawing.Rectangle crop1 = new IronSoftware.Drawing.Rectangle(x: x1, y: y1, width: x2-x1, height: y2-y1);
Imports IronBarCode
Private x1 As Integer = 62
Private y1 As Integer = 29
Private x2 As Integer = 345
Private y2 As Integer = 522
Private crop1 As New IronSoftware.Drawing.Rectangle(x:= x1, y:= y1, width:= x2-x1, height:= y2-y1)
应用作物区域并读取条形码
一旦我们完成了定义需要 IronBarcode 读取的 CropRegions 的艰苦工作,我们就可以将对象应用到 条码阅读器选项
中的参数。 条码阅读器.读取()
method. The code snippet below shows
:path=/static-assets/barcode/content-code-examples/how-to/set-crop-region-apply-CropRegion.cs
using IronBarCode;
using System;
int x1 = 62;
int y1 = 29;
int x2 = 345;
int y2 = 522;
IronSoftware.Drawing.Rectangle crop1 = new IronSoftware.Drawing.Rectangle(x: x1, y: y1, width: x2 - x1, height: y2 - y1);
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
CropArea = crop1
};
var result = BarcodeReader.Read("sample.png", options);
foreach (var item in result)
{
Console.WriteLine(item.Value);
}
Imports IronBarCode
Imports System
Private x1 As Integer = 62
Private y1 As Integer = 29
Private x2 As Integer = 345
Private y2 As Integer = 522
Private crop1 As New IronSoftware.Drawing.Rectangle(x:= x1, y:= y1, width:= x2 - x1, height:= y2 - y1)
Private options As New BarcodeReaderOptions() With {.CropArea = crop1}
Private result = BarcodeReader.Read("sample.png", options)
For Each item In result
Console.WriteLine(item.Value)
Next item
在上面的代码片段中,我们使用了于 矩形
于 条码阅读器选项
对象作为 作物面积
属性。然后,我们利用这一 条码阅读器选项
对象作为参数 条码阅读器.读取()
method to apply the CropArea in the image and read the barcodes inside.