Enhanced .Net Barcode Library for Desktop App Development

A couple of weeks ago, we released a new version of Dynamic .NET TWAIN – the .NET component for capturing images from scanners and webcams. The SDK includes an enhanced .Net barcode add-on for both barcode encoding and decoding. In this article, we will show you the strengths of the new barcode library, and how to utilize the barcode APIs in a C# project.

Dynamsoft .NET Barcode SDK vs. ZXing

The open source project ZXing is a popular multi-format 1D/2D barcode image processing library implemented in Java. There is also a ZXing .Net project on CodePlex. Based on ZXing, we have made a lot of improvements to Dynamsoft .NET Barcode SDK.  Here are some testing results between the two SDKs:

Different Barcode Formats

Barcode Formats

Blurred Barcodes

Blurred Barcode

Big Image with Barcode: 8000*8000

Big Images

Scaled Barcodes: 1000*1000

Scaled Barcode

We are still taking the effort to improve the performance of our barcode library, and make it seamlessly work with the .NET TWAIN scanning module. The following sample code will show you how easy it is to implement a .Net barcode application.

Sample Code

Read a Barcode:

            string dllPath = Application.ExecutablePath;
            int index = dllPath.LastIndexOf("\\");
            dynamicDotNetTwain1.BarcodeDllPath = dllPath.Substring(0, index); // load the Dynamsoft barcode library

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title = "Open Image";

                if (dlg.ShowDialog() == DialogResult.OK) // load an image
                {
                    Bitmap bitmap = new Bitmap(dlg.FileName);
                    this.pictureBox1.Image = bitmap;
                    this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; // set the image in PictureBox

                    dynamicDotNetTwain1.MaxImagesInBuffer = 1;
                    bool isLoaded = dynamicDotNetTwain1.LoadImage(dlg.FileName); // load the image to Dynamic .NET TWAIN component
                
                    Dynamsoft.DotNet.TWAIN.Barcode.Result[] aryResult = dynamicDotNetTwain1.ReadBarcode(dynamicDotNetTwain1.CurrentImageIndexInBuffer, Dynamsoft.DotNet.TWAIN.Enums.Barcode.BarcodeFormat.All); // read barcode

                    StringBuilder strText = new StringBuilder();
                    for (int i = 0; i < aryResult.Length; i++)
                    {
                        Dynamsoft.DotNet.TWAIN.Barcode.Result objResult = aryResult[i];
                        strText.AppendFormat("      Result " + (i + 1) + "\r\n");
                        strText.AppendFormat("      BarcodeFormat: " + objResult.BarcodeFormat.ToString() + "\r\n");
                        strText.AppendFormat("      Text read: " + objResult.Text + "\r\n");
                    }
                    result.Text = strText.ToString(); // display the result
                }
            }

Generate a QR Code:

            string dllPath = Application.ExecutablePath;
            int index = dllPath.LastIndexOf("\\");
            dynamicDotNetTwain1.BarcodeDllPath = dllPath.Substring(0, index); // load the barcode library

            using (OpenFileDialog dlg = new OpenFileDialog())

            {
                dlg.Title = "Open Image";

                if (dlg.ShowDialog() == DialogResult.OK) // load an image
                {
                    string text = textBox1.Text;
                    float scale = 3; // specify the barcode scale
                    short sImageIndex = 0;
                    dynamicDotNetTwain1.MaxImagesInBuffer = 1;

                    bool isLoaded = dynamicDotNetTwain1.LoadImage(dlg.FileName); // load the image to Dynamic .NET TWAIN component
                    dynamicDotNetTwain1.AddBarcode(sImageIndex, Dynamsoft.DotNet.TWAIN.Enums.Barcode.BarcodeFormat.QR_CODE, text, "", 0, 0, scale); // Specify the barcode format as QR code. Merge the generated barcode with the background image
                    Image img = dynamicDotNetTwain1.GetImage(sImageIndex);
                    this.pictureBox2.Image = img; // display the final image
                    this.pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                }
            }

Try yourself

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.

Subscribename@email.com