使用Aspose.BarCode 和 Aspose.Words从Word文档中识别条码

来源:慧都控件网

在本文中,我们将使用Aspose.BarCodeAspose.Words这两个控件实现从Word文档中识别条码。步骤如下:

1、使用Aspose.Words for .NET从文档中提取图像

2 、以流的形式保存提取的图像

3 、将图像以流的形式传递到Aspose.BarCode for .NET中

4 、从图像中读取条码

[C#]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Load the word document
Document wordDocument = new Document( "Invitation.doc" );
// get all the shapes
NodeCollection shapes = wordDocument.GetChildNodes(NodeType.Shape, true , false );
// loop through all the shapes
foreach (Shape shape in shapes)
{
     // check if it has an image
     if (shape.HasImage)
     {
         // save the image in memory stream
         MemoryStream imgStream = new MemoryStream();
         shape.ImageData.Save(imgStream);
  
         // recognize the barcode from the image stream above
         BarCodeReader reader = new BarCodeReader( new Bitmap(imgStream), BarCodeReadType.Code39Standard);
         while (reader.Read())
         {
             Console.WriteLine( "Codetext found: " + reader.GetCodeText());
         }
         // close the reader
         reader.Close();
     }

[VB.NET]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
' Load the word document
Dim wordDocument As Document = New Document( "Invitation.doc" )
' get all the shapes
Dim shapes As NodeCollection = wordDocument.GetChildNodes(NodeType.Shape, True , False )
' loop through all the shapes
For Each shape As Shape In shapes
    ' check if it has an image
    If shape.HasImage Then
       ' save the image in memory stream
       Dim imgStream As MemoryStream = New MemoryStream()
       shape.ImageData.Save(imgStream)
  
       ' recognize the barcode from the image stream above
       Dim reader As BarCodeReader = New BarCodeReader( New Bitmap(imgStream), BarCodeReadType.Code39Standard)
       Do While reader.Read()
          Console.WriteLine( "Codetext found: " & reader.GetCodeText())
       Loop
       ' close the reader
       reader.Close()
    End If
Next shape
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Aspose.BarCode 是一款功能强大的条形码识别工具。它可以轻松地读取和解码不同类型的条形码,如二维码、一维码、GS1 DataBar 和 PDF417 等。通过使用 Aspose.BarCode,开发人员可以轻松实现条形码识别和数据提取功能。 Aspose.BarCode 提供了多种条形码读取方法,可以根据需要选择合适的方法。首先,我们可以通过指定文件路径或 URL 直接从图像文件或网页上读取条形码。其次,我们还可以从 Bitmap、Stream 或字节流读取条形码。这使得 Aspose.BarCode 可以与各种应用程序集成,无论是 Web 应用程序还是桌面应用程序。 使用 Aspose.BarCode 识别条形码非常简单。我们只需要创建一个 BarCodeReader 对象,并将要处理的图像文件或流传递给它。然后,我们可以使用 Read 方法读取条形码数据。如果图像存在多个条形码,我们可以使用 GetAllBarCodes 方法返回所有条形码的数据。接下来,我们可以使用返回的数据进行后续处理,如保存到数据库或显示在用户界面上等。 除了简单的条形码识别外,Aspose.BarCode 还提供了许多高级特性。例如,我们可以设置识别区域以减少识别时间和误差率。我们还可以设置识别算法,以提高对损坏、模糊或变形的条形码的识别率。此外,我们还可以将识别结果转换为各种格式,如文本、XML 或 JSON。 总之,Aspose.BarCode 是一款功能强大、易于使用的条形码识别工具。它为开发人员提供了简单而灵活的方式来读取和解码条形码,无论是从图像文件还是流使用 Aspose.BarCode,我们可以轻松地将条形码识别功能集成到我们的应用程序,以满足各种数据提取需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值