libdmtx .NET Wrapper

1. libdmtx-net Installation

  1. Compile the libdmtx solution.
  2. Compile the solution.
  3. Add a reference to Libdmtx.Net.dll in you're project. (Make sure you copy libdmtx.dll into the same directory as your binaries).

1.1 Compiler Options

WARNING: A user has reported memory access violations when using a .NET application and the .NET Wrapper when compiling with default settings in Visual C++ 2008 Express Edition. The defaults for the Release build have compile time optimizations enabled. When they are turned off the application behaves as expected.

To turn them off use the Debug build or under the libdmtx project property pages choose, Configuration: Release in the drop down, Configuration Properties > C/C++ > Optimization in the tree view, and set Optimization to Disabled (/Od) and set Enable Intrinsic Functions to No, click Apply and recompile.

2. Dependencies

Requires .NET Framework 2.0 (or higher) and C runtime library, for example Microsoft Visual C++ Runtime.

3. Using

Using is very similar to the command line utilities dmtxread and dmtxwrite. This disallows to use the library as smart as with C API, but saves unmanaged calls from .NET which cost some overhead.

3.1. Decoding

// C# Example
Libdmtx.DecodeOptions o = new Libdmtx.DecodeOptions();
Bitmap b = new Bitmap(@"bitmap.png");
Libdmtx.DmtxDecoded[] res = Dmtx.Decode(b, o);
for (uint i = 0; i < res.Length; i++) 
  string str = Encoding.ASCII.GetString(res[i].Data).TrimEnd('\0');
  Console.WriteLine("Code " + i + ": " + str);

3.2. Encoding

// C# Example
Libdmtx.EncodeOptions o = new Libdmtx.EncodeOptions();
byte[] dataToEncode = Encoding.ASCII.GetBytes("Hello World!");
Libdmtx.DmtxEncoded en = Dmtx.Encode(dataToEncode, o);
pictureBox1.Image = en.Bitmap;

3.3. More Information

See the source, LibDmtx.cs is a good start.

4. VB.NET example for use in ASP.NET page.

         If FileUpload1.HasFile Then
            Dim fExtension As String
            Dim fFileName As String = FileUpload1.PostedFile.FileName
            fExtension = Path.GetExtension(FileUpload1.PostedFile.FileName)
            Dim fileBytes(FileUpload1.PostedFile.InputStream.Length) As Byte
            FileUpload1.PostedFile.InputStream.Read(fileBytes, 0, fileBytes.Length)
            Dim collector As New MemoryStream(fileBytes)
            Dim gImage As Bitmap
            gImage = Bitmap.FromStream(collector)

            Dim bDecode As New Libdmtx.DecodeOptions
            bDecode.CodeType = Libdmtx.CodeType.DataMatrix
            bDecode.MaxCodes = 1
            Dim pDecode As Libdmtx.DmtxDecoded() = Libdmtx.Dmtx.Decode(gImage, bDecode)

            Dim cString As String
            cString = String.Empty
            For Each thing In pDecode
                cString = cString & Encoding.ASCII.GetString(thing.Data)
            Label1.Text = cString
            Label2.Text = pDecode.Length.ToString
        End If

5. Anything Else?

Is something missing from these instructions? If you spent hours searching for a solution that you feel should be included here then please update this page directly.

[Add your documentation here…]

6. This Document

Updates to this page ultimate feed into the wrapper/net/README file that is distributed with the source package. If you are looking for information specific to an older release, please refer to this file as it exists in that package version.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License