C#/VB.NET 读取条码类型及条码在图片中的坐标位置

打印 上一主题 下一主题

主题 1812|帖子 1812|积分 5436

我们在创建条形码时,如果以图片的方式将创建好的条码保存到指定文件夹路径,可以在程序中直接加载图片使用;已生成的条码图片,需要通过读取图片中的条码信息,如条码类型、条码绘制区域在图片中的四个顶点坐标位置等,可参考本文中的方法。
:读取时,也支持读取二维码类型。
 
引入dll

调用API:Spire.Barcode for .NET
两种方法:
★ 1. 在VS中通过“管理NuGet包”,搜索“Spire.Barcode”安装;
或者通过PM控制台安装:
PM> NuGet\Install-Package Spire.Barcode -Version 6.8.0
★ 2. 官网下载包安装到本地路径,然后将安装路径下的Spire.Barcode.dll手动引入到VS程序。
 
读取条码类型及顶点坐标

C#
  1. using Spire.Barcode;
  2. using Spire.Barcode.Settings;
  3. using System.Drawing;
  4. namespace GetBarcode
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //加载条码图片
  11.             BarcodeInfo[] barcodeInfos = BarcodeScanner.ScanInfo("img.png");
  12.             for (int i = 0; i < barcodeInfos.Length; i++)
  13.             {
  14.                 //获取条码类型
  15.                 BarCodeReadType barCodeReadType = barcodeInfos[i].BarCodeReadType;
  16.                 System.Console.WriteLine("Barcode Type is:" + barCodeReadType.ToString());           
  17.                 //获取条形码图片中的四个顶点坐标位置
  18.                 Point[] vertexes = barcodeInfos[i].Vertexes;
  19.                 //输出结果
  20.                 for(int j = 0; j < vertexes.Length; j++)
  21.                 {
  22.                     System.Console.WriteLine(vertexes[j]);
  23.                 }               
  24.                 System.Console.ReadKey();
  25.             }
  26.         }
  27.     }
  28. }
复制代码
VB.NET
  1. Imports Spire.Barcode
  2. Imports Spire.Barcode.Settings
  3. Imports System.Drawing
  4. Namespace GetBarcode
  5.     Class Program
  6.         Private Shared Sub Main(args As String())
  7.             '加载条码图片
  8.             Dim barcodeInfos As BarcodeInfo() = BarcodeScanner.ScanInfo("img.png")
  9.             For i As Integer = 0 To barcodeInfos.Length - 1
  10.                 '获取条码类型
  11.                 Dim barCodeReadType As BarCodeReadType = barcodeInfos(i).BarCodeReadType
  12.                 System.Console.WriteLine("Barcode Type is:" + barCodeReadType.ToString())
  13.                 '获取条形码图片中的四个顶点坐标位置
  14.                 Dim vertexes As Point() = barcodeInfos(i).Vertexes
  15.                 '输出结果
  16.                 For j As Integer = 0 To vertexes.Length - 1
  17.                     System.Console.WriteLine(vertexes(j))
  18.                 Next
  19.                 System.Console.ReadKey()
  20.             Next
  21.         End Sub
  22.     End Class
  23. End Namespace
复制代码
读取结果:

 
—END—
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

道家人

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表