如何定义条码作物区域以加快读取速度

This article was translated from English: Does it need improvement?
Translated
View the article in English

海瑞尔 哈西米 本 奥马尔

IronBarcode 最重要的功能之一是用户可以指定裁剪区域。 该功能的目的是通过使用 "IronSoftware.Drawing.Rectangle "对象,使 IronBarcode 只读取图像中裁剪区域指定的特定条形码或区域。使用该功能不仅可以减少读取错误,还可以提高读取性能。

适用于的C# NuGet库

安装使用 NuGet

Install-Package BarCode
Java PDF JAR

下载 DLL

下载DLL

手动安装到你的项目中

适用于的C# NuGet库

安装使用 NuGet

Install-Package BarCode
Java PDF JAR

下载 DLL

下载DLL

手动安装到你的项目中

开始在您的项目中使用IronPDF,并立即获取免费试用。

第一步:
green arrow pointer

查看 IronBarcodeNuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。

适用于的C# NuGet库 nuget.org/packages/BarCode/
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)
VB   C#

应用作物区域并读取条形码

一旦我们完成了定义需要 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
VB   C#

在上面的代码片段中,我们使用了于 矩形条码阅读器选项 对象作为 作物面积 属性。然后,我们利用这一 条码阅读器选项 对象作为参数 条码阅读器.读取() method to apply the CropArea in the image and read the barcodes inside.

海瑞尔 哈西米 本 奥马尔

软件工程师

像所有优秀的工程师一样,Hairil 是一个热衷学习的人。他正在精进自己的 C#、Python 和 Java 知识,并利用这些知识为 Iron Software 团队成员增添价值。Hairil 毕业于马来西亚的马来西亚工艺大学(Universiti Teknologi MARA),获得了化学与工艺工程学士学位,然后加入了 Iron Software 团队。