libdmtx .NET Wrapper

1. libdmtx-net Installation

  1. Compile the libdmtx solution.
  2. Compile the libdmtx.net 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).

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)
            Next
            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.

page_revision: 8, last_edited: 1258115255|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License