ZXing.NET - specify location of barcode

Aug 31, 2012 at 5:36 PM
Edited Aug 31, 2012 at 6:30 PM

I need specify location of barcode for MultiFormatReader. For example I know that format of image is A4 and barcode is always left upper corner.

I would like specify location for barcode because on image are more than one barcode.

I tried use crop method of BinaryBitmap class and cut barcode from image.:

code is here:


LuminanceSource luminance = new BitmapLuminanceSource(bmp);

var binarizer = new HybridBinarizer(luminance);

var bb = new BinaryBitmap(binarizer);

var cropBitmap = bb.crop(0, bb.Height, 150, 80);

var data = multiReader.decodeWithState(cropBitmap);


I would like crop barcode from left upper corner. I need crop rectangle width 12cm, height 10cm.
I don’t how specify these condition.

I need crop area in red rectangle:


If I set left = 0, height = BinaryBitmap.Height it is this left upper corner of image?


public BinaryBitmap crop(
	int left,
	int top,
	int width,
	int height


Thank you for help

Aug 31, 2012 at 9:16 PM

Please try the following code snippet:

         var reader = new BarcodeReader(null,
                                        bmp =>
                                              var uncroppedImage = new BitmapLuminanceSource(bmp);
                                              return uncroppedImage.crop(0, 0, uncroppedImage.Width/2, uncroppedImage.Height/5);
         var data = reader.Decode(bmp);

The upper left corner is 0, 0. I would calculate the new height and width relative to the original size (uncroppedImage.Width/2, uncroppedImage.Height/5).

- Michael

Sep 1, 2012 at 7:55 PM

@micjahn: Thank you for quick response. My problem is now fixed. :)