Barcode Xpress for Linux v14.0 - Updated January 7, 2025
Developer Guide / How To / Create a Barcode
Create a Barcode
  1. The first step to creating a barcode is to decide what type of barcode to use and what the contents will be. This is done by creating a BX_CreateParameters structure.
  2. Set the type of barcode and the value you want to create. Barcode types that can be written are listed in the Supported Barcode Types section.

For a full list of properties see the BX_CreateParameters structure.

To create:

  • a bitmap image file of the barcode call the BX_create_file function.
  • an in memory bitmap structure of the barcode call the BX_create_dib function.

The following code example illustrates creating a 1D barcode.

//create a copy of the default parameters.
BX_CreateParameters bxCreateParams = BX_DefaultCreateParameters;
//set some of the 1D parameters:
bxCreateParams.Params1D.CheckSum = false; //don't print the checksum for barcode types that have an optional checksum character.
bxCreateParams.Params1D.TextNotchPercent = 25;
// create the status and results variable to capture the results:
BX_CreateResult createResult;
BX_Status resultOfCreation = BX_Status_OK;
// initialize the error count:
createResult.ErrorCount = 0;

   //call BX_create_dib or BX_create_file to create a barcode image:
resultOfCreation = BX_create_file(params, fl, &createResult);

   // check that the file was created successfully.
if (createResult.ErrorCount == 0 && resultOfCreation == BX_Status_OK)
{
    printf("Successfully created file \"%s\".\n", fl);
}
else
{
    ///there was an error of some kind:
    printf("Failed to create file %s. ErrorNumber = %d\n", fl, resultOfCreation );
    //print the error details:
    for (resultLen; resultLen < createResult.ErrorCount; resultLen++)
    {
        printf("Error creating file file %d: %s.\n", resultLen, createResult.BarcodeErrors[resultLen].errorID);
    }
}