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

Direction of 1D barcode

Aug 2, 2012 at 12:01 AM

Is it possible to get the direction of the barcode?

E.g. a vertical barcode (then, the direction should return "top to bottom")

or a rotated barcode (then, the direction should return "right to left")?

In the Result class, there's no direction info.

Aug 2, 2012 at 1:58 AM
Edited Aug 2, 2012 at 4:02 AM

There is a ResultMetadataType.ORIENTATION metadata which IS suppose to keep the barcode orientation.

However, after testing it out, I find that it is used sparingly in the codes i.e. it detect only for "right to left" barcode.

If a barcode is vertical (i.e. top to bottom), it is not used (or maybe haven't code it in yet?).

How does the algorithm detect that the barcode is top to bottom?

Aug 2, 2012 at 8:34 PM

The core zxing library adds the orientation info only for 1D barcodes. Second you have to set TryHarder to true which is needed for rotation of the barcodes.
BUT I added rotation of barcodes to the BarcodeReader class without the need of TryHarder.
I didn't set the orientation meta data until today. I added the necessary changes for setting the data.
Not sure if it now works right in every situation.

Aug 3, 2012 at 1:24 AM

Actually, I've already added the codes to make it work yesterday and tested it on 1D barcodes for all 4 directions.

Pls see if u need to update it into subversion

I made the changes in BarcodeReader.cs in the function "public Result Decode(Bitmap barcodeBitmap)"


if (result != null || !luminanceSource.RotateSupported)           


//start change

if (result.ResultMetadata != null)               


IDictionary<ResultMetadataType, object> metadata = result.ResultMetadata;                   

if (metadata.ContainsKey(ResultMetadataType.ORIENTATION))                   


int degree = (int)result.ResultMetadata[ResultMetadataType.ORIENTATION];                        result.ResultMetadata[ResultMetadataType.ORIENTATION] = degree + (rotationCount * 90);                   





result.putMetadata(ResultMetadataType.ORIENTATION, (rotationCount * 90));               


//end changes


Aug 3, 2012 at 6:34 PM

I merged your solution with my changes. Should work now as expected.

Aug 4, 2012 at 1:12 PM

Ok, will test out the new codes.

Sep 4, 2012 at 5:41 AM
long1000 wrote:

Ok, will test out the new codes.

Great, it works.

Sep 4, 2012 at 8:16 AM

Btw, the reverse() function in BitArray.cs 

is it doing a 180 degree rotation or a mirror image?

Sep 4, 2012 at 8:52 PM

reverse() doesn't rotate or mirror the image.
The class BitArray is used for encoded data not for the resulting bitmap. The class BitMatrix is used for the pre-rendering representation of the barcode bitmap. But that class has no reverse or rotate method.