How to change color of generating qr from black to red or green or blue(another color of black)

Posted by Ahmedsa under Windows Forms on 3/11/2017 | Points: 10 | Views : 2403 | Status : [Member] | Replies : 1
How to change color of generating qr to red or green or blue(another color of black)

I working in visual studio 2015 windows form application

I generating qr using message toolkit library and it working good without any problem

only i face problem how to change color qr code using message toolkit

my code

I try to replace color to red
Result of code below change all picture to red color
and this is wrong

MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
encoder.QRCodeScale = 8;
Bitmap bmp = ChangeColor(encoder.Encode(textBox1.Text), Color.Red);
pictureBox1.Image = bmp;
bmp.Save(sv.FileName, ImageFormat.Jpeg);

public static Bitmap ChangeColor(Bitmap scrBitmap, Color color)
//You can change your new color here. Red,Green,LawnGreen any..
Color newColor = color;
Color actualColor;
//make an empty bitmap the same size as scrBitmap
Bitmap newBitmap = new Bitmap(scrBitmap.Width, scrBitmap.Height);
for (int i = 0; i < scrBitmap.Width; i++)
for (int j = 0; j < scrBitmap.Height; j++)
//get the pixel from the scrBitmap image
actualColor = scrBitmap.GetPixel(i, j);
// > 150 because.. Images edges can be of low pixel colr. if we set all pixel color to new then there will be no smoothness left.
if (actualColor.A > 150)
newBitmap.SetPixel(i, j, newColor);
newBitmap.SetPixel(i, j, actualColor);
return newBitmap;

Result wrong result


Posted by: Vibhore89 on: 4/4/2017 [Member] Starter | Points: 25

Using free Barcode API (, you will be able to change the background or fore color of QR code image.

see this link:

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response