This project has moved. For the latest updates, please go here.

Reading QRcode in an image, which have more than one barcode

May 9, 2013 at 10:45 AM
Hi,

As I know, IBarcodeReader.Decode() function reads all the barcodes there are on an image.

If one image have more than one barcode(maybe incould code39, QRcode.....),
but I only want to read QRcode, how can i do ?

I had use WindowsFormsDemo to read it, but only read first bracode.
and then, I have test QRCodeMultiReader, but i don't how to use it.

Anybody having the same problem? Can advise?

thanks.
Coordinator
May 9, 2013 at 11:00 AM
If you want to find only one code inside an image with a specific type, you can use the following code snippet:
var reader = new BarcodeReader
   {
      PossibleFormats = new List<BarcodeFormat>
         {
            BarcodeFormat.QR_CODE
         }
   };
var result = reader.Decode(bitmap);
If you want to find more than one code inside an image you have to use the following snippet:
var reader = new BarcodeReader
   {
      PossibleFormats = new List<BarcodeFormat>
         {
            BarcodeFormat.QR_CODE
         }
   };
var results = reader.DecodeMultiple(bitmap);
The WindowsFormsDemo has an options dialog where you can enable multiple codes per image.
May 9, 2013 at 12:13 PM
Hi micjahn,

I want to to find only one code inside an image with a QR Code type.
I have try both of you suggest code, but it don't work.
Can you advise again ?
using ZXing;
using ZXing.Common;
using ZXing.Multi;
using ZXing.Multi.QrCode;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {



        private readonly IBarcodeReader barcodeReader;
        private readonly IList<ResultPoint> resultPoints;
        private readonly IDictionary<DecodeHintType, object> hints;
  
        public Form1()
        {
            InitializeComponent();
            resultPoints = new List<ResultPoint>();
         
            barcodeReader = new BarcodeReader { AutoRotate = true, TryHarder = true };
            hints = new Dictionary<DecodeHintType, object>();

            barcodeReader.ResultPointFound += point =>
            {
                if (point == null)
                    resultPoints.Clear();
                else
                    resultPoints.Add(point);
            };
            barcodeReader.ResultFound += result =>
            {
                txtType.Text = result.BarcodeFormat.ToString();
                txtDecoderContent.Text = result.Text;
            };
        }

        private void button1_Click(object sender, EventArgs e)
        {
             var fileName = "C:\\test.PNG";
             Decode((Bitmap)Bitmap.FromFile(fileName));
        }

  
        private void Decode(Bitmap image)
        {
            resultPoints.Clear();
         /*   var reader = new BarcodeReader
            {
                PossibleFormats = new List<BarcodeFormat>
                 {
                    BarcodeFormat.QR_CODE
                 }
            };
        
            var result = reader.Decode(image);
         */ 
            var result = barcodeReader.Decode(image);
            var timerStart = DateTime.Now.Ticks;
            var timerStop = DateTime.Now.Ticks;

            if (result == null)
            {
                txtDecoderContent.Text = "No barcode recognized";
            }
            labDuration.Text = new TimeSpan(timerStop - timerStart).Milliseconds.ToString("0 ms");
         }
    }
}
Coordinator
May 9, 2013 at 12:20 PM
Can you give me a sample image which you tried?
May 10, 2013 at 2:10 AM
Image
Coordinator
May 10, 2013 at 8:14 AM
The image has a very low quality.
I don't think that any other decoder has a chance to find the qr code at the bottom right corner.
You need an image with a higher resolution.
May 11, 2013 at 12:43 AM
Can you try this file, I think last file had be change quality by the website.

Download file

thanks!!
Coordinator
May 11, 2013 at 5:47 PM
I got a result, QR Code with DSDIVIDE_A12345670.
var reader = new BarcodeReader
{
   TryHarder = true,
   PossibleFormats = new List<BarcodeFormat>
   {
      BarcodeFormat.QR_CODE
   }
};
var result = reader.Decode(image);