C#: Online Guide
How To: Barcode Reader
QR Code
QR Code
  |  
Home ›› XImage.Barcode Reader ›› C# Barcode Reader: QR Code

C# Imaging - Read 2D QR Code in C#.NET


Sample C# Code to Decode QR Code from Document Image




C# Imaging - QR Code Reading Control



C#.NET BarcodeRead Add-on from RasterEdge DocImage SDK for .NET is a reliable, accurate & fast barcode detecting and reading control, designed specifically for .NET class applications (including ASP.NET web service and Windows application). This barcode decoding control can read QR Code barcode from scanned image files (including tiff, png, jpeg, png and bmp) and common documents (including PDF, MS Word, Excel & PowerPoint).Besides, its ability to scan QR Code from a full page or certain specified region using C# code makes it extremely easy for users to optimize the barcode reading rate based on different applications.


QR Code, short for Quick Response Code, has become one of the most commonly used 2D barcode types in the world based on its huge information storage, high-level error correction level and square barcode pattern.

As QR Code has a wide valid data scope, thus, people often encode a website link into QR Code. Then one can easily visit this website by just scanning the QR code barcode, instead of entering the url in the web browser. Therefore, QR Code has been widely used in the marketing and advertising field as a promotion tool.


Besides, if you want to know more detailed information on barcode reading & recognition from PDF document using C#.NET, please follow the link to read step-to-step tutorial and sample C# code.




C#.NET QR Code Reader Control Features



Mature QR Code barcode reading library for C#.NET imaging project with reasonable licensing


Compatible with .NET Framework 2.0 & above, suitable for Visual Studio 2005 & greater


Detect and read all QR Code barcodes from documents and image files using C#.NET


Extract and return recognized QR Code barcode value into data string using C# code


Read & decode QR Code barcode at any orientation from document image in C#.NET


Allow users to specify an area on the document or image to recognize QR Code barcode




Steps to Read/Scan Data Matrix from Image/PDF/TIFF/Office File



Load an image or a document(PDF, TIFF, Word, Excel, PowerPoint).


Get a Bitmap or BasePage used to decode or read barcode.


Set the barcode reader settings.


Call the following static method in BarcodeReader.cs to read or scan barcode from Bitmap or BasePage.


  public static Barcode[] ReadBarcodes(ReaderSettings settings, BasePage page)


  public static Barcode[] ReadBarcodes(ReaderSettings settings, Bitmap image)


The barcode information will be saved in the array of Barcode object. While, if you read barcodes information from the BasePage failed, you can try as follows:


  Convert BasePage to Bitmap with higher resolution by Calling method ConvertToImage(int resolution) in the BasePage.cs:



            //Convert page to bitmap.
            //The default resolution is 96, if youo set the resolution higher, it will be better to read or scan barcode.
            Bitmap bmp = page.ConvertToImage(192);

            //  read all barcodes in the page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(settings, bmp);

            foreach (Barcode barcode in barcodes)
            {
                Console.WriteLine("Data: " + barcode.DataString);
            }



If you want to have a try, please refer to the following demo codes.


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




Read QR Code from Scanned Image File Using C#



Using this .NET barcode reader control, you can easily detect and decode all QR Code barcodes from loaded image file using C# code. Supported image file formats are png, jpeg, bmp, tiff and gif. The sample C# code below can help you detect all QR Code barcodes from png and return the decoding values to data string.


Add necessary references to your C#.NET project. Right-click the project and select "Add Reference..." to locate and add the following DLLs as project references;


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XImage.BarcodeScanner.dll


Use corresponding namespaces;


  using RasterEdge.XImage.BarcodeScanner;




            Bitmap bmp = new Bitmap(inputDirectory + "Sample_Barcode.png");
            //  config reader setting
            ReaderSettings settings = new ReaderSettings();
            //  define the type of barcode to scan
            settings.AddTypesToRead(BarcodeType.QRCode);

            //  read all barcodes in the document
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(settings, bmp);

            foreach (Barcode barcode in barcodes)
            {
                Console.WriteLine("Data: " + barcode.DataString);
            }





C#: DLLs for QR Code Barcode Scanning from Document(TIFF, PDF, Office)



In order to run the following demo codes reading QR Code from document, the steps as follows are necessary.


Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.XImage.BarcodeScanner.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.XImage.BarcodeScanner;


  using RasterEdge.Imaging.Basic;




Read QR Code from TIFF Image File Using C#



With RasterEdge .NET Barcode Reader SDK, users are allowed to reading QR Code not only from png, jpeg, bmp and gif image files, but also tiff images. This is the C# demo code for reading QR Code from tiff image file.


Add references(Extra):


  RasterEdge.XDoc.TIFF.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.TIFF;




            // load TIFF document
            TIFFDocument doc = new TIFFDocument(inputDirectory + "Sample_Barcode.tif");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.QRCode);

            // read barcode from tiff page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Read QR Code from PDF File Using C# Code



This C#.NET barcode scanning control can also detect all the QR Code barcodes automatically from scanned PDF document file. Besides, by default, the barcode reader and scanner will detect all the QR Code barcodes from the whole PDF page with five algorithms.


Add references(Extra):


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.PDF;




            // load PDF document
            PDFDocument doc = new PDFDocument(inputDirectory + "Sample_Barcode.pdf");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.QRCode);

            // read barcode from PDF page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Recognize QR Code from Word Document Using C#



This barcode reader control also supports detecting & recognizing QR Code from Word document in C#.NET class application. The QR Code barcode reader scanning area can be accurately specified using C# code. There is no fixed outputting ways to export the QR Code scanning results. Here, we output the decoding result to data string using C# code.


Add references(Extra):


  RasterEdge.XDoc.Word.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.Word;




            // load Word document
            DOCXDocument doc = new DOCXDocument(inputDirectory + "Sample_Barcode.docx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.QRCode);

            // read barcode from Word page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Scan QR Code on a Certain Excel Page in C#.NET



Apart from MS Word document, users also are supposed to use RasterEdge .NET Imaging Barcode Reading control to decode QR Code on a certain Excel document page with folloiwng C# sample code.


Add references(Extra):


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.Excel;




            // load Excel document
            XLSXDocument doc = new XLSXDocument(inputDirectory + "Sample_Barcode.xlsx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.QRCode);

            // read barcode from Excel page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }





Recognize QR Code from PPTX Document in C#.NET



Users can detect and scan QR Code barcode from MS PowerPoint slide/page in high performance by combining RasterEdge .NET Imaging Barcode Reader and MS PPTX Document dll. Please see following demo code in C# class for detailed guide.


Add references(Extra):


  RasterEdge.XDoc.PowerPoint.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


Use corresponding namespaces(Extra):


  using RasterEdge.XDoc.PowerPoint;




            // load PowerPoint document
            PPTXDocument doc = new PPTXDocument(inputDirectory + "Sample_Barcode.pptx");

            // get the page you want to scan
            BasePage page = doc.GetPage(0);

            // set reader setting
            ReaderSettings setting = new ReaderSettings();

            // set type to read
            setting.AddTypesToRead(BarcodeType.QRCode);

            // read barcode from PowerPoint page
            Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

            foreach (Barcode barcode in barcodes)
            {
                // print the loaction of barcode on image
                Console.WriteLine(barcode.BoundingRectangle.X + "  " + barcode.BoundingRectangle.Y);

                // output barcode data onto screen 
                Console.WriteLine(barcode.DataString);
            }