Barcode Xpress for Linux v13.9 - Updated
Create Your First Project
Getting Started > Create Your First Project

Introduction

Reading your first barcode with Barcode Xpress for Linux takes only a few minutes. There are two easy ways to get started.

Use our GitHub sample

We have an easy to use sample for getting started on GitHub. Just clone the repo and get started in no time.

Create your own project

Creating your own project is simple. There are basically 3 steps to creating your own project.

  1. Download Barcode Xpress for Linux and extract the archive wherever you like. You can get it here: https://www.accusoft.com/products/barcode-xpress-collection/barcode-xpress/#see-it-in-action
  2. Write a simple program using C++.
  3. Compile and run it with g++.

Setup

First, we'll create our new project inside the "samples" directory that is created when you extract the archive. Create and navigate to a new directory called "readbarcodes-simple".

Now, create a new file called readbarcodes-simple.cpp. Inside that file, paste the following code:

#include "barcodexpress.h"
#include "stdio.h"

int main(const int argc, const char **argv) {

    BX_AnalyzeParameters params = BX_DefaultAnalyzeParameters;
    BX_AnalyzeResult result;

    params.BarcodeTypes = BX_BarcodeType_All;
    params.Orientation = BX_Orientation_HorizontalVerticalDiagonal;

        BX_Status status = BX_analyze_file( &params, "../images/Barcode-All-Supported-Types.bmp", &result );

    for( int i=0; i<result.BarcodeResultsLength; ++i ) {
        BX_BarcodeResult *res = &result.BarcodeResults[i];
        printf("\t\tValue: %s\n", res->Value);
    }

    BX_free_analyze_result( &result );

    return 0;
}

Compile

gcc -o readbarcodes-simple readbarcodes-simple.cpp -I../../include -L../../bin -Wl,-rpath=../../bin/ -lbarcodexpress -lpthread -ldl

Run

./readbarcodes-simple

Important code explained

Here we declare two important variables. First, we declare params. This struct contains parameters that allows you to customize how you search for barcodes. Next, we delcare result. This is a struct that contains the results of barcode recognition after we call BX_analyze_file

BX_AnalyzeParameters params = BX_DefaultAnalyzeParameters;
BX_AnalyzeResult result;

Here we specify the orientation in which we want to search, and the barcode types we wish to find. Basically, we're looking for all barcodes in all orientations.

params.BarcodeTypes = BX_BarcodeType_All;
params.Orientation = BX_Orientation_HorizontalVerticalDiagonal;

BX_analyze_file is the most important function of this program, it is the function that actually does the work of looking for barcodes on an image. To use it, we pass in the address of our params struct, the path to a BMP file, and the address of our results struct. BX_analyze_file also returns a value indicating whether or not any error were encountered during barcode recognition. 0 means no errors were encounters, every other value indicates a specific error.

BX_Status status = BX_analyze_file( &params, "./images/Barcode-All-Supported-Types.bmp", &result );

Is this page helpful?
Yes No
Thanks for your feedback.