0

Im using Zxing.net with c# to decode 1D and 2D codes. For some reason the BarcodeReader method does not accept Binarybitmap, it only accepts a normal bitmap. I want to use binary bitmap because zxing has an inbuilt binarizer function.

Here is my code:

      public void ProcessCode(Bitmap image, BarcodeFormat format)
     {

        LuminanceSource source;
        source = new ZXing.BitmapLuminanceSource(image);
        var bitmapr = new BinaryBitmap(new GlobalHistogramBinarizer (source));        
        var bcreader = new BarcodeReader { AutoRotate = false };
        bcreader.Options.PossibleFormats = new List<BarcodeFormat>();
        bcreader.Options.PossibleFormats.Add(QrCode);
        result = bcreader.Decode(bitmapr);
        resultp = result.ResultPoints;           
    }

The error I get is : cannot convert from 'ZXing.BinaryBitmap' to 'System.Drawing.Bitmap'

1 Answers1

0

The BarcodeReader implementation doesn't accept a BinaryBitmap instance. You can use your bitmap instance directly or you can use a bitmap luminance source. If you want to use a different binarizer you can use a function delegate when calling the specific constructor of BarcodeReader.

But in my opinion, it should be fine if you use the following code snippet:

 public void ProcessCode(Bitmap image, BarcodeFormat format)
 {
    var bcreader = new BarcodeReader { AutoRotate = false };
    bcreader.Options.PossibleFormats = new List<BarcodeFormat>();
    bcreader.Options.PossibleFormats.Add(QrCode);
    result = bcreader.Decode(image);
    resultp = result.ResultPoints;           
 }
Michael
  • 2,361
  • 1
  • 15
  • 15