How to change color qr generating to another color of black-VBForums
Results 1 to 2 of 2

Thread: How to change color qr generating to another color of black

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2016
    Posts
    37

    How to change color qr generating to another color of black

    I working in visual studio 2015 windows form application

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

    I face only one problem i need to change color of qr to another color different to

    black as blue or red or green like that

    so that how to do color qr code using messagetoolkit

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

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,119

    Re: How to change color qr generating to another color of black

    If that QRCodeEncoder class doesn't provide the ability to specify a colour, you could simply change the colour of the pixels one by one:
    csharp Code:
    1. private void ChangePixelColour(Bitmap bmp, Color originalColour, Color newColour)
    2. {
    3.     for (var x = 0; x < bmp.Width; x++)
    4.     {
    5.         for (var y = 0; y < bmp.Height; y++)
    6.         {
    7.             if (bmp.GetPixel(x, y) == originalColour)
    8.             {
    9.                 bmp.SetPixel(x, y, newColour);
    10.             }
    11.         }
    12.     }
    13. }
    GetPixel and SetPixel are slow but performance should be good enough for what is likely to be a relatively small image.
    Last edited by jmcilhinney; Mar 12th, 2017 at 05:38 AM. Reason: Replaced VB code with C#
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.