How to print, customize barcode with colors using C#?
Barcode bar & space colors options in C#?
Using OnBarcode C# Barcode library, you can easily generate and customize QR Code and barcode bar module and space colors in C# ASP.NET web and desktop applications.
- Create a new QRCode object with a data message "OnBarcode.com"
- Apply property ForeColor (barcode bar module color) with red color
- Apply property BackColor (barcode space module color with white color
- Use method drawBarcode() to print QR Code to a png image file
QRCode barcode = new QRCode(); barcode.Data = "OnBarcode.com"; barcode.ForeColor = Color.Red; barcode.BackColor = Color.White; barcode.OutputFileFormat = FileFormat.PNG; barcode.drawBarcode("C://Output//barcode-bar-space-color-sample.png");
How to generate barcode with transparent background color using C#?
This C#.NET barcode generator suite enables users to create barcode images with transparent background.
Currently, barcode image in png file format which supports transparent background setting.
To generate transparent background barcode image in C# class, you need apply the four barcode property settings.
- BackColor: Its value shall be Color.Transparent.
- ForeColor: Barcode bar module color.
- TextColor: It usually is the same as ForeColor.
- Format: The image format shall be FileFormat.PNG
Here is an EAN-13 barcode generation C# example.
Please copy the following Visual C# demo code to your project for a transparent barcode symbol implementation. You can store the scannable barcode images in database with further C# coding.
Please copy the following Visual C# demo code to your project for a transparent barcode symbol implementation. You can store the scannable barcode images in database with further C# coding.
Linear barcode = new Linear(); barcode.Data = "123456789012"; barcode.Type = BarcodeType.EAN13; barcode.ForeColor = Color.White; barcode.BackColor = Color.Transparent; barcode.TextColor = Color.White; barcode.OutputFileFormat = FileFormat.PNG; barcode.drawBarcode("C://Output//barcode-transparency-sample.png");
How to print, customize 1d barcode text color using C#?
Colorful linear/1d barcode image setting in C# class is very simple. You can set the barcode color properties
background color, foreground color, and human readable text color in your C# barcode program.
Just follow the quick C# barcode manual below.
Firstly, please downlolad the C# barcode library and add .NET barcode generator dll into your C# project reference. In the following example,
we will create a Code 128 with colors customized.
- ForeColor: Barcode bar module color. It is in red color here.
- BackColor: Barcode space module color. It is in white color here.
- TextColor: Linear / 1D barcode Human Readable Interpretation text color. It usually is the same as ForeColor.
Linear barcode = new Linear(); barcode.Type = BarcodeType.CODE128; barcode.Data = "Code-128"; barcode.ForeColor = Color.Red; barcode.BackColor = Color.White; barcode.TextColor = Color.Red; barcode.OutputFileFormat = FileFormat.PNG; barcode.drawBarcode("C://Output//barcode-text-color-sample.png");
How to generate, print barcode in EPS file with CMYK colors applied using C#?
When you are generating QR Code or barcode in EPS files, you can choose draw and print barcode colors in RGB or CMYK colors.
- Apply property UseCMYKInEPS to true. The barcode library will automatically convert ForeColor and BackColor from RGB colors to CMYK colors.
QRCode barcode = new QRCode(); barcode.Data = "QR Code"; barcode.ForeColor = Color.Blue; barcode.BackColor = Color.White; barcode.UseCMYKInEPS = true; barcode.OutputFileFormat = FileFormat.EPS; barcode.drawBarcode("C://Output//barcode-eps-cmyk-color-sample.eps");
Good and bad colors for barcode
Color selection is a critical step in designing qualified barcode labels. All selected colors must maintain high compatibility with barcode scanners.
Insufficient color contrast (the luminance and hue difference between two adjacent colors) is the primary cause of unreadable barcodes. A low contrast effect between barcode bar patterns and the label background will hinder the normal decoding process of scanners.
This guide systematically introduces applicable and inapplicable color schemes for barcodes to prevent scanning failure in practical use.
Insufficient color contrast (the luminance and hue difference between two adjacent colors) is the primary cause of unreadable barcodes. A low contrast effect between barcode bar patterns and the label background will hinder the normal decoding process of scanners.
This guide systematically introduces applicable and inapplicable color schemes for barcodes to prevent scanning failure in practical use.
Guiding Principles for Barcode Color Selection
Color contrast serves as the core judgment indicator for barcode color matching.
The classic combination of a white background and black barcode bars is the most industry-recommended scheme.
Standard barcode scanners operate based on the light reflection principle. Scanners can effectively identify barcode information when the label background reflects light fully and the barcode bars absorb light without reflection.
Most conventional scanners have weak recognition capabilities for yellow and red hues, resulting in poor decoding accuracy. Black and blue-based dark colors can be stably captured and identified by most barcode scanning equipment.
Standard barcode scanners operate based on the light reflection principle. Scanners can effectively identify barcode information when the label background reflects light fully and the barcode bars absorb light without reflection.
Most conventional scanners have weak recognition capabilities for yellow and red hues, resulting in poor decoding accuracy. Black and blue-based dark colors can be stably captured and identified by most barcode scanning equipment.
Note: Adopt light-colored backgrounds and dark-colored barcode bars for standard barcode label production.
Good color combinations
Dark colors including black, blue, and green are applicable for barcode bar colors.
| Black & White | Black & Red | Black & Yellow |
|
|
|
| Green & White | Green & Red | Green & Yellow |
|
|
|
Bad color combinations
If the barcode colors are both light background and light barcode bars, or both dark background and dark barcode bars,
the matching modes will cause insufficient color difference, resulting in unrecognizable barcode information by the scanner.
| Red & White | Lavender & White | Yellow & White |
|
|
|
| Black & Green | Black & Brown | Black & Blue |
|
|
|
Note: We strongly recommend you to test printed barcodes with multiple types of barcode scanners and barcode reader applications to ensure readability.
How to Use C# to Encode Raster Image Formats (JPEG, PNG, GIF, BMP, TIFF)
Users can use C# code to generate a barcode image and encode it into several image file format:
- JPEG/JPG: a commonly used method of lossy compression for digital images.
- PNG: Portable Network Graphics is a raster-graphics file format that supports lossless data compression.
- BMP/Bitmap: The BMP file format or bitmap, is a raster graphics image file format used to store bitmap digital images.
- GIF: The Graphics Interchange Format is a bitmap image format.
- TIFF: Tagged Image File Format, a file format for storing images.
Please see as below. (UPC-A is the sample barcode type encoding 12 number digit with check character automatically added).
Developers can adjust other barcode settings, in order to enlarge barcode picture to fixed size in C# by setting width/height, manage barcode label rotation, set unit of measure to centimeter/pixel, or define encrypted barcode color.
Linear upc_a = new Linear(); upc_a.Type = BarcodeType.UPCA; upc_a.Data = "12345678901"; // Encode UPC-A barcode into jpeg file format and save it to C:\ upc_a.OutputFileFormat = FileFormat.JPG; upc_a.drawBarcode("c://csharp_upca.jpeg"); //Encode UPC-A barcode into png, gif, bmp or tiff file format: upc_a.OutputFileFormat = FileFormat.PNG; upc_a.drawBarcode("c://csharp_upca.png"); upc_a.OutputFileFormat = FileFormat.GIF; upc_a.drawBarcode("c://csharp_upca.gif"); upc_a.OutputFileFormat = FileFormat.BMP; upc_a.drawBarcode("c://csharp_upca.bmp"); upc_a.OutputFileFormat = FileFormat.TIF; upc_a.drawBarcode("c://csharp_upca.tiff");
High resolution (dpi) barcode image in C#
To create a barcode image for printing, your barcode image resolution should be higher than the printer's resolution. To create a high resolution barcode image,
you need apply the following two barcode properties:
- OutputFileFormat: You need choose raster image format as
PNG,JPG, orBMP. Please do not chooseGIF. The GIF image format does not support image resolution setting. - Resolution: The value of the resolution should be larger than your printer's resolution.
How to Use C# to generate barcodes in Vector images (SVG & EPS)
Using C# Barcode Generator library, you can easily generate barcodes with vector image formats:
- SVG: Scalable Vector Graphics (SVG) is a web-friendly vector file format. It is the only vector image supported by web browsers.
- EPS: Encapsulated PostScript (EPS) is a Document Structuring Convention (DSC) conforming PostScript document format usable as a graphics file format.
How to create barcodes in SVG file format using C#
Using C# barcode generator library, you can easily output barcodes to:
View the barcode in SVG format in the web browser (Chrome)
- a SVG file
- SVG stream object in C#
- SVG data in byte array in C# program
- Set the barcode property
OutputFileFormatwith the valueFileFormat.SVG
QRCode barcode = new QRCode(); barcode.Data = "https://www.onbarcode.com"; barcode.OutputFileFormat = FileFormat.SVG; barcode.drawBarcode("C://Output//barcode-in-svg.svg");
View the barcode in SVG format in the web browser (Chrome)
Print QR Code to SVG file format, and output to a Stream object
Using the mothod
Using the mothod
drawBarcode(Stream fileStream), you can create and print barcode to Stream object in C# ASP.NET, WinForms application.
public void drawBarcode(Stream fileStream)
Print QR Code to SVG file format, and output to a binary data
In the C# source code below, it will create and output barcode to byte array object using method
In the C# source code below, it will create and output barcode to byte array object using method
drawBarcodeAsBytes(), and you can further process the barcode in C# application.
byte[] dataBytes = barcode.drawBarcodeAsBytes();
How to create barcodes in EPS file format using C#
Same as SVG, using C# barcode generator library, you can easily output barcodes to:
- a EPS file
- EPS stream object in C#
- EPS data in byte array in C# program
With property OutputFileFormat to FileFormat.EPS, the printed barcode will be in EPS vector image file format using C#.
View the barcode in EPS format using the Acrobat software.
QRCode barcode = new QRCode(); barcode.Data = "https://www.onbarcode.com"; barcode.OutputFileFormat = FileFormat.EPS; barcode.drawBarcode("C://Output//barcode-in-eps.eps");
View the barcode in EPS format using the Acrobat software.
With property OutputFileFormat to FileFormat.EPS, the printed barcode will be in EPS format in a Stream object.
Print barcode in EPS format to a Stream object
Using the mothod
Using the mothod
drawBarcode(Stream fileStream), you can create and print barcode to Stream object in C# ASP.NET, WinForms application.
public void drawBarcode(Stream fileStream)
Print barcode in EPS format to a binary data
In the following C# source code, it will create and output QR Code in EPS file format, and output to byte array object using method
In the following C# source code, it will create and output QR Code in EPS file format, and output to byte array object using method
drawBarcodeAsBytes(), and you can further process the barcode in C# application.
byte[] dataBytes = barcode.drawBarcodeAsBytes();
Summary
All the included components comply with VB.NET, Visual C# .NET. These .NET barcode generation controls support quick creation of linear & bidimensional bar code that can be customized to meet required specifications. The software supports C# barcode ASP.NET, C# barcode graphics design in Win Forms, and C# barcode reporting display.
OnBarcode also provide other examples regarding Visual C# barcode generation, please see below:
- Generating Barcode in Visual C# - tutorial for generating batch hgih-quality barcode images in C# program
- Creating Barcode in C# ASP.NET - tutorisl for streaming barcodes in ASP.NET web service or html page with C#
- Painting Barcode in C# WinForms - tutorial for drawing multiple barcodes images in C# Windows Forms programming
- Encoding Barcode in C# Programs - tutorial for creating bulk GS1 barcode or barcodes encoding Unicode using C#
Common Asked Questions
Why is a barcode black and white in color?
2D and 1D Barcodes usually both are black bars and white space because this creates the highest contrast and is the easiest for barcode reader software and barcode scanners to decode.
Using C# Barcode library, by default you will generate 2d and 1d barcodes in black and white in C# apps. You can customize the barcode module and space colors through
property
ForeColor, and BackColor in C# codes.
What colors should barcodes be avoided?
When you are selecting colors for barcodes, it is important that you have selected colors with high contrast.
If the bar and space module colors are both too light or too dark, the barcode scanner may not be able to decode.
Can barcodes be grey?
Yes. You can choose gray color as barcode bar modules color or space color. However you need make sure the space color and bar color have high contrast.
In C# asp.net, windows project, you can apply the printed barcode bar color using property
ForeColor, and barcode space color using property
BackColor.
Do QR Code colors matter?
QR codes don't have to be black and white in order to be scannable. You can choose right colors to increase brand recognition. However you
need choose color combination with high contrast for QR Code bar and space colors.
Using C# Barcode Generator library, you can customize and apply the generated QR Code bar color using property
ForeColor, and barcode space color using property
BackColor.
What is SVG?
SVG stands for Scalable Vector Graphics. It is a vector image format which is perfect for barcode image rendering and viewing in web browser.
C# Barcode Generator library supports QR Code and other 2d, 1d barcode generation in SVG image format in C# class.
Is SVG better than PNG?
SVG is a vector image format, which is considered a more advanced image file type than PNG. Both image formats can be used in web browser.
OnBarcode C# Barcode library supports QR Code, Code 128, and 20+ 2d, linear barcodes generations in PNG and SVG image formats in C# ASP.NET, MVC, web and Windows applications.