7

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.

Is there any free SDK for reading 2d Barcode from images?

Rand Random
  • 7,300
  • 10
  • 40
  • 88
Praveen Kumar
  • 1,576
  • 8
  • 31
  • 47
  • 1
    http://www.codeproject.com/Articles/10162/Creating-EAN-13-Barcodes-with-C, http://community.bartdesmet.net/blogs/bart/archive/2006/09/18/4432.aspx, http://www.idautomation.com/formscontrols/free/, ... which spec are you trying to follow? –  Apr 10 '12 at 07:31
  • i need to read 2D datamatrix from an image – Praveen Kumar Apr 10 '12 at 08:38
  • which barcode-spec do you want to meet? code39, code128, code49, pdf417, qr, data-matrix? ... not very clear to me ... but i guess you are after Data Matrix (http://en.wikipedia.org/wiki/Data_Matrix) - am i right? –  Apr 10 '12 at 13:06

2 Answers2

4

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!

  • i've tried to use it, but it couldn't decode unicode chars properly (it was 2 years ago, i guess) - i encoded string, which contained russian chars and it failed to give me proper result on decoding. – cookieMonster Apr 11 '12 at 12:10
  • 1
    @cookieMonster actually DataMatrix.net is `A C#/.net-library for encoding and decoding DataMatrix codes (based on a .net-port of libdmtx).` - so it's based on your suggested libdtmx. btw - did you file a bug-ticket @ DataMatrix.net when coming across russian chars? –  Apr 11 '12 at 12:38
  • it may be 'based on', but it's not a .net port, libdmtx has it's own port and it works better in terms of decoding. – cookieMonster Apr 11 '12 at 12:43
  • I am able to read max. 2 barcodes only from an image. What could be the reason? – NinethSense Dec 20 '13 at 06:27
  • 1
    @NinethSense as i am not the author of this assembly, you may want to directly contact them on their sourceforge site (either via a ticket or a thread in their forum (http://sourceforge.net/p/datamatrixnet/discussion/1030456)) –  Dec 20 '13 at 08:26
2

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.

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.

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

cookieMonster
  • 508
  • 6
  • 15