Our Customers
Contact Us Email: support@barcodelib.com
Home > .NET Barcode > C# Barcoding Guide > How to Set & Adjust Barcode Image Color in C#.NET Projects
Download Barcode for .NET Suite Trial

How to create styled QR Code using C# in ASP.NET Core?

Use C#.NET Class Code to Change & Customize QR Code Color Settings
  • Highly-credited C#.NET QR Code barcode image generator component
  • Easy to change & reset generated QR Code colors in C#.NET applications
  • Customize colors of QR Code in ASP.NET & WinForms projects using C# code
  • Able to generate & print QR Code image with different background colors
  • Free to set module color of created QR Code images using C#.NET class library
  • Generated colorful QR Code images are compatible with industry standards
C#.NET QR Code Barcode Generator Overview
C#.NET QR Code Barcode Generator from BarcodeLib.com is a time-tested QR Code barcoding component since 2003. It can not only generate high-quality QR Code images but makes it extremely easy for users to change & set QR Code image colors, including background color and bar color.
Generate & Change QR Code Color in C# Class
Before customizing QR Code color settings, users have to install .NET, C#.NET barcode generating dlls first.

Installation

  • Locate Barcodelib.Barcode.ASP.NET.dll or BarcodeLib.Barcode.WinForms.dll from downloaded trial package.
  • Integrate either of those two barcode generating dlls into your C# project by adding reference.
  • Integrate either of those two barcoding dlls into the Visual StudioToolbox.

Implementation

You can change QR Code image colors easily using following free sample C# class codes.
     // Generate & print QR Code image using C#
     BarcodeLib.Barcode.QRCode qrbarcode = new BarcodeLib.Barcode.QRCode();
     qrbarcode.Encoding = BarcodeLib.Barcode.QRCodeEncoding.Auto;
     qrbarcode.Data = "ABCD1234abcd";
     qrbarcode.ModuleSize = 3;
     qrbarcode.LeftMargin = 12;
     qrbarcode.RightMargin = 12;
     qrbarcode.TopMargin = 12;
     qrbarcode.BottomMargin = 12;

     // Change module color & background color of QR Code
     qrbarcode.BackgroundColor = System.Drawing.Color.White;
     qrbarcode.ModuleColor = System.Drawing.Color.Blue;

     // Save generated QR Code image to pgn image format file
     qrbarcode.drawBarcode("c:/qrcode.png");
Generate & Print Colorful QR Code in ASP.NET Web Page & IIS

Change QR Code Barcode Colors in ASP.NET Web Page

  • Add "Barcodelib.Barcode.ASP.NET.dll" to your ASP.NET project by reference.
  • Add "Barcodelib.Barcode.ASP.NET.dll" to the VS toolbox by choosing item.
  • Copy files "qrcode.aspx", "qrcode.aspx.cs" from folder barcode in the downloaded package to your ASP.NET project folder.
  • Drag QRCodeASPNET to your ASP.NET web site, and change QR code colors through "Properties" window.

Change QR Code Barcode Colors in IIS

  • Find folder "barcode" from downloaded trial package and copy it to your IIS folder, eg. C:\inetpub.
  • Create a new virtual directory in your IIS, name it "barcode", and connect it to the above "barcode" folder in inetpub. Then, restart IIS.
  • Open your web browser and navigate to:
    "http://YourDomain:port/barcode/qrcode.aspx?Data=ABCD1234abcd&ModuleSize=3 &LeftMargin=12&RightMargin=12&TopMargin=12&BottomMargin=12&BackgroundColor=FFFFFF&ModuleColor=000079"
  • To insert this QR Code image in your aspx or html page, simply pass the url to IMG tag or src value.
    For example: <img src= http://YourDomain:port/barcode/qrcode.aspx?Data=ABCD1234abcd&ModuleSize=3 &LeftMargin=12&RightMargin=12&TopMargin=12&BottomMargin=12&BackgroundColor=FFFFFF&ModuleColor=000079>
    This method will not generate any barcode images in your IIS server side.
Change & Customize QR Code Color in C#.NET WinForms
  • Add BarcodeLib.Barcode.WinForms.dll to your C#.NET Windows Forms project reference.
  • Add BarcodeLib.Barcode.WinForms.dll to Visual Studio Toolbox.
  • Drag the QRCodeWinForm to your windows form.
  • Adjust module color & background color using "Properties" window.
Tutorail: How to create styled QR Code using C# in ASP.NET Core web app?
Here we will create a new ASP.NET Core web app, and learn how to create and customize styled QR Code on the razor page using C# codes.

1. Create a new ASP.NET Core web app & Install barcode library and NuGet package

We have already provided a detailed tutorial to generate and customize barcodes online on the razor pages in ASP.NET Core web app.

You can view the details here:
How to create barcodes in ASP.NET Core web app using C# barcode generator library?

And follow the first two steps: Create a new web app, and Install C# barcode library and NuGet package

During creating the new ASP.NET Core project, you need change the new project name as "BarcodeLib.Create.StyledQRCodeASPNETCoreDemo".

2. Add C# codes to create, customized styled QR Code on a Razor page

Copy the following code to file "Index.cshtml"

@page
@model IndexModel
@{
    ViewData["Title"] = "BarcodeLib Styled QR Code Generator in ASP.NET Core web app";
}

<div class="text-center">
    <form asp-page="./Index" method="post">
        <br />
        Barcode data:
        <input type="text" id="tb1" name="tbBarcodeData" style="width: 600px; " asp-for="@Model.BarcodeData" />
        <br />
        <br />
        <input type="submit" value="Create Styled QR Code" />
    </form>
    <br />
    <img src="data:image/png;base64,@Model.BarcodeImage"
         width="@Model.BarcodeWebDisplayWidth" height="@Model.BarcodeWebDisplayWidth" />
</div>
Copy the following code to file "Index.cshtml.cs"

using BarcodeLib.Barcode;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Drawing.Imaging;

namespace BarcodeLib.Create.StyledQRCodeASPNETCoreDemo.Pages
{
    public class IndexModel : PageModel
    {
        public String BarcodeData { get; set; } = "https://www.barcodelib.com";
        public String BarcodeImage { get; set; } = "";

        public float BarcodeWebDisplayWidth { get; set; } = 0f;


        public Task<IActionResult> OnGet()
        {
            byte[] dataBytes = getBarcodeInBytes();

            BarcodeImage = System.Convert.ToBase64String(dataBytes);

            return Task.FromResult<IActionResult>(Page());
        }

        public Task<IActionResult> OnPost()
        {
            this.BarcodeData = Request.Form["tbBarcodeData"].ToString();

            byte[] dataBytes = getBarcodeInBytes();

            BarcodeImage = System.Convert.ToBase64String(dataBytes);

            return Task.FromResult<IActionResult>(Page());
        }

        private byte[] getBarcodeInBytes()
        {
            BarcodeLib.Barcode.QRCode styledQR = new BarcodeLib.Barcode.QRCode();

            styledQR.Data = this.BarcodeData;

            styledQR.LogoImage = new System.Drawing.Bitmap("C://Projects//Test-Files//barcodelib-logo.png");

            styledQR.LogoRenderSize = new System.Drawing.SizeF(300, 300);

            styledQR.ModuleColor = System.Drawing.Color.Blue;

            styledQR.ImageFormat = ImageFormat.Png;

            styledQR.UOM = UnitOfMeasure.INCH;
            styledQR.ResizeImage = true;
            styledQR.ImageWidth = 1.5f;
            styledQR.ImageHeight = 1.5f;
            styledQR.Resolution = 900;
            styledQR.ResizeImagePaddingTransparent = true;

            this.BarcodeWebDisplayWidth = styledQR.ImageWidth * 96f;

            return styledQR.drawBarcodeAsBytes();
        }
    }
}

3. Run the ASP.NET Core web app to generate styled QR Code in browser

Press Ctrl+F5 in Visual Studio to run the finished asp.net core web app.

You will find the QR Code generated with a logo rendered in the center and with blue bar modules.

Conclusion

It is really easy to generate styled QR Code online using C# barcode generator library. If you need add more options to customize QR Code online in web browser, we have provided a complete step by step tutorial here:
How to create barcodes online in browser in C# ASP.NET Core web app?




All Supported Linear & 2D Barcode Types
Linear Barcode Types:
Matrix Barcode Types: