C# 从图像读取二维条码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10084824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading 2D Barcode from Images
提问by Praveen Kumar
I need a library to read 2D barcode (datamatrix) from images on C# project (windows Forms). I tried using some SDKs, but the SDKs I tried are not free.
我需要一个库来从 C# 项目(Windows 窗体)上的图像读取二维条码(数据矩阵)。我尝试使用一些 SDK,但我尝试的 SDK 不是免费的。
Is there any free SDK for reading 2d Barcode from images?
是否有用于从图像中读取二维条码的免费 SDK?
采纳答案by Andreas Niedermair
There's an example available:
using DataMatrix.net; // Add ref to DataMatrix.net.dll
using System.Drawing; // Add ref to System.Drawing.
[...]
// ---------------------------------------------------------------
// Date 180310
// Purpose Get text from a DataMatrix image.
// Entry sFileName - Name of the barcode file (PNG, + path).
// Return The text.
// Comments See source, project DataMatrixTest, Program.cs.
// ---------------------------------------------------------------
private string DecodeText(string sFileName)
{
DmtxImageDecoder decoder = new DmtxImageDecoder();
System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(sFileName);
List<string> oList = decoder.DecodeImage(oBitmap);
StringBuilder sb = new StringBuilder();
sb.Length = 0;
foreach (string s in oList)
{
sb.Append(s);
}
return sb.ToString();
}
You'll need DataMatrix.net!
您将需要DataMatrix.net!
回答by cookieMonster
Best free Datamatrix coder\decoder that i've used is libdmtx: http://www.libdmtx.org/. It has c# wrapper, so feel free to use it. I can't write sample code right now, but if you won't be able to handle it yourself, i'll help you a bit later with that.
我使用过的最好的免费 Datamatrix 编码器\解码器是 libdmtx:http: //www.libdmtx.org/。它有 c# 包装器,所以可以随意使用它。我现在无法编写示例代码,但如果您无法自己处理,稍后我会帮助您。
EDIT: libdmtx comes with console utils - if you will be able to read your barcodes with console app, you surely will read it using code.
编辑:libdmtx 附带控制台实用程序 - 如果您能够使用控制台应用程序读取条形码,您肯定会使用代码读取它。
EDIT2:
Here's code samples: http://libdmtx.wikidot.com/libdmtx-net-wrapper
I wonder if you have pictures containing some other info, except the barcode. The thing is - i don't know any free\open source lib to handle finding barcode on a picture, containing any other data properly.
And here's the link to other datamatrix implementations: http://www.libdmtx.org/resources.php
EDIT2:这是代码示例:http: //libdmtx.wikidot.com/libdmtx-net-wrapper
我想知道您是否有包含除条形码之外的其他信息的图片。问题是 - 我不知道任何免费\开源库来处理在图片上查找条形码,正确包含任何其他数据。这是其他数据矩阵实现的链接:http: //www.libdmtx.org/resources.php

