Search code examples
c#zxing

Autorotate option for GenericMultipleBarcodeReader in Zxing.Net


How can I set the hint 'AutoRotate' for 'GenericMultipleBarcodeReader' in Zxing.net. I have set Try_Harder = true. But no results for detecting multiple 1d/2d barcodes from a rotated image. If the image is aligned properly it gives the results.

Edit: In 'GenericMultipleBarcodeReader' I am using 'ByQuadrantReader'. This could detect barcodes and QR codes from properly aligned images. For a rotated image it could not find anything.

MultiFormatReader multiReader = new MultiFormatReader();
ZXing.Multi.GenericMultipleBarcodeReader byquadReader = new ZXing.Multi.GenericMultipleBarcodeReader(new ByQuadrantReader(multiReader));              
Dictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType, object>();
hints.Add(DecodeHintType.TRY_HARDER, true);
List<BarcodeFormat> formats = new List<BarcodeFormat>();
formats.Add(BarcodeFormat.All_1D);
formats.Add(BarcodeFormat.QR_CODE);
hints.Add(DecodeHintType.POSSIBLE_FORMATS, formats);
****
byquadresults = byquadReader.decodeMultiple(binaryBitmap, hints);

Could any one please help me.


Solution

  • AutoRotate can only be used with the BarcodeReader class.

         var bitmap = (Bitmap)Bitmap.FromFile("<path to your image file>");
         var reader = new BarcodeReader
         {
            AutoRotate = true,
            Options = new DecodingOptions
            {
               TryHarder = true,
               PossibleFormats = new List<BarcodeFormat>
               {
                  BarcodeFormat.All_1D,
                  BarcodeFormat.QR_CODE
               }
            }
         };
    
         var results = reader.DecodeMultiple(bitmap);
    

    If you want to use the ByQuadrantReader you have to replace the line

    var reader = new BarcodeReader...
    

    with

    var reader = new BarcodeReader(new ByQuadrantReader(new MultiFormatReader()), null, null)...