Get Barcode Placement Region and Orientation Angle

Get Barcode Placement and Orientation Information

To retrieve information about the placement region and orientation angle of a source barcode, Aspose.BarCode for JavaScript via C++ provides a group of properties called RegionParameters. This group stores the following details:

  • Quadrangle – an object that bounds the barcode.
  • Rectangle – an object that bounds the barcode.
  • Points – an array of points that make up the barcode.
  • Angle – the orientation angle in degrees.

The following code sample demonstrates how to retrieve information about the barcode placement region and orientation angle from a sample barcode image.

How to get BarCodeInstance

var gen = new BarCodeInstance.BarcodeGenerator("Code128", "Aspose1234");
gen.Parameters.Barcode.XDimension = "2px";
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display barcode image

// Read Code 128 barcode with region information
var reader = new BarCodeInstance.BarCodeReader(gen.GenerateBarCodeImage(), "Code128");
reader.ReadBarCodes();
for (var i = 0; i < reader.FoundCount; i++) {
    var result = reader.FoundBarCodes(i);
    console.log(`CodeType: ${result.CodeType}`);
    console.log(`CodeText: ${result.CodeText}`);
    console.log(`Quadrangle: ${result.Region.Quadrangle.toString()}`);
    console.log(`Angle: ${result.Region.Angle.toString()}`);
    console.log(`Rectangle: ${result.Region.Rectangle.toString()}`);
    let ptStr = "";
    for(var j = 0; j < result.Region.PointsCount; j++)
    {
        var pt = result.Region.GetPoint(j);
        ptStr += pt.toString() + " ";
    }
    console.log(`Points: ${ptStr}`);
}

gen.delete();
reader.delete();