Tutorial: Detect, Read, and Write Barcodes – Console C#

Speed and accuracy are key when encoding and decoding the machine readable data found within barcodes. LEADTOOLS offers top-of-the-line computer vision barcode libraries that are faster and more reliable than any other barcode SDK on the market, ensuring that you always get the best possible results.

Whether it’s the PDF417 barcode found on the back of your driver’s license, a QR barcode on a sticker, or the UPC barcode on the back of a product, LEADTOOLS can support it as well as over 100 different barcode symbologies.

With as little as four lines of code, you can determine a barcode’s symbology, bounds, and much more. All supported symbologies can be quickly found and decoded, no matter the angle or color. To increase accuracy, LEAD offers many different configuration options such as EnableDoublePass, EnablePreprocessing, and EnableFastMode to modify the behavior of the barcode decoding to fit your application needs.

The C# code below shows you everything needed to detect and decode barcodes from an image. If you want a complete step-by-step tutorial, check out our tutorials on how to Detect and Extract Barcodes and Write 1D and 2D Barcodes to an Image.

static void ReadBarcode(RasterImage image) 
    BarcodeEngine barcodeEngineInstance = new BarcodeEngine(); 
        BarcodeData[] dataArray = barcodeEngineInstance.Reader.ReadBarcodes(image, LeadRect.Empty, 0, null); 
        StringBuilder sb = new StringBuilder(); 
        sb.AppendFormat("{0} barcode(s) found", dataArray.Length); 
        for (int i = 0; i < dataArray.Length; i++) 
            BarcodeData data = dataArray[i]; 
            sb.AppendFormat("Symbology: {0}, Location: {1}, Data: {2}", data.Symbology.ToString(), data.Bounds.ToString(), data.Value); 
    catch (Exception ex) 

static void WriteUPCABarcode(RasterImage image) 
   BarcodeData data = new BarcodeData 
      Symbology = BarcodeSymbology.UPCA, 
      Value = "01234567890", 
      Bounds = new LeadRect(10, 10, 600, 200) 
   OneDBarcodeWriteOptions options = new OneDBarcodeWriteOptions 
      EnableErrorCheck = true, 
      TextPosition = BarcodeOutputTextPosition.Default 
   barcodeEngine.Writer.WriteBarcode(image, data, options); 

Try it out!

To test this for yourself, make sure to get the latest LEADTOOLS SDK evaluation for free from our site, if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.


Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

Stay tuned for more tutorials that programmers can use to develop applications that directly impact data capture, recognition, exchange, and other pressing business needs.


Technical Marketing Engineer

This entry was posted in Barcode and tagged , , , . Bookmark the permalink.

Leave a Reply

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