Colorize any Part of the Barcode Image

Skip to end of metadata
Go to start of metadata
Normally, barcodes are generated and printed in black and white colors. But, what if it is required to generate a colored barcode?

Keeping this possible requirement in mind, Aspose.BarCode gives free hand to developers to change the colors of:

  • Barcode
  • Code text
  • Barcode Background
  • Barcode Border
  • Caption

BarCodeBuilder class has following methods that are used to colorize different parts of a barcode as follows:

  • setForeColor() method to assign any color to the Barcode
  • setCodeTextColor() method to assign any color to the Code text of the barcode
  • setBackColor() method to set the Background color of the barcode
  • setBorderColor() method to set the Border color of the barcode

Developers can select any desired color using Java.awt.Color (part of Java) and then pass that selected color to any of the methods (setForeColor(), setCodeTextColor(), setBackColor ()or setBorderColor()) according to their custom requirements.

Programming Sample
[Java]
//Instantiate barcode object
BarCodeBuilder bb = new BarCodeBuilder();

//Set the background color of the barcode
bb.setBackColor(Color.YELLOW);

//Set the foreground color of the barcode
bb.setForeColor(Color.BLUE);

//Set border's color
bb.setBorderColor(Color.RED);

//Set the code text's color
bb.setCodeTextColor(Color.RED);

//Caption's color
bb.getCaptionAbove().setForeColor(Color.darkGray);
bb.getCaptionBelow().setForeColor(Color.CYAN);
 

The resulting colored barcode generated by executing the above code is shown in the figure below:

Figure: Colored barcode generated after example code execution


Here are some barcode samples based on extreme color settings:

Figure: barcode color gallery



Figure: barcode color gallery



Figure: barcode color gallery

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.