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

All barcode classes ( BarCodeBuilder , BarCodeControl and BarCodeWebControl ) provided by Aspose.BarCode have some common properties that are used to colorize different parts of a barcode as follows:

  • ForeColor property to assign any color to the Barcode
  • CodeTextColor property to assign any color to the Code text of the barcode
  • BackColor property to set the Background color of the barcode
  • BorderColor property to set the Border color of the barcode
Programming Sample

Developers can select any desired color using System.Drawing.Color structure (part of Microsoft .NET Framework) and then assign that selected color to any of the properties (ForeColor, CodeTextColor, BackColor or BorderColor) according to their custom requirements.

[C#]
//Instantiate barcode object
BarCodeBuilder bb = new BarCodeBuilder();

//Set the Code text for the barcode
bb.CodeText = "1234567";

//Set the symbology type to Code128
bb.SymbologyType = Symbology.Code128;

//Set background color of the barcode
bb.BackColor = System.Drawing.Color.Yellow;

//Set color (fore color) of the barcode
bb.ForeColor = System.Drawing.Color.Blue;

//Set border color of the barcode
bb.BorderColor = System.Drawing.Color.Red;

//Set color of the code text of the barcode
bb.CodeTextColor = System.Drawing.Color.Red;

//Save the image to your system
//and set its image format to Jpeg
bb.Save("barcode.jpg",
   System.Drawing.Imaging.ImageFormat.Jpeg);
 


[VB.NET]
'Instantiate barcode object
Dim bb As BarCodeBuilder = New BarCodeBuilder()

'Set the Code text for the barcode
bb.CodeText = "1234567"

'Set the symbology type to Code128
bb.SymbologyType = Symbology.Code128

'Set background color of the barcode
bb.BackColor = System.Drawing.Color.Yellow

'Set color (fore color) of the barcode
bb.ForeColor = System.Drawing.Color.Blue

'Set border color of the barcode
bb.BorderColor = System.Drawing.Color.Red

'Set color of the code text of the barcode
bb.CodeTextColor = System.Drawing.Color.Red

'Save the image to your system
'and set its image format to Jpeg
bb.Save("barcode.jpg",
   System.Drawing.Imaging.ImageFormat.Jpeg)
 

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.