codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.61k stars 1.1k forks source link

BitmapByteQRCode.HexColorToByteArray swaps R and B in RGB colors #139

Closed Blackbaud-ChristiSchneider closed 5 years ago

Blackbaud-ChristiSchneider commented 6 years ago

Type of issue

[x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

BitmapByteQRCode.GetGraphic(20, "#ff0000", "#ffffff") should generate a red graphic, just like BitmapByteQRCode.GetGraphic(20, new byte[] { 0xff, 0x00, 0x00 }, new byte[] { 0xff, 0xff, 0xff }).

Current Behavior

The graphic is generated as blue (#0000ff).

Possible Solution (optional)

Change https://github.com/codebude/QRCoder/blob/master/QRCoder/BitmapByteQRCode.cs line 85 to set byteColor[i] instead of byteColor[2-i]

Steps to Reproduce (for bugs)


        private IActionResult GetPlainQRCode(string url)
        {
            PayloadGenerator.Url generator = new PayloadGenerator.Url(url);
            string payload = generator.ToString();

            using (var qrGenerator = new QRCodeGenerator())
            {
                using (var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q))
                {
                    using (var qrCode = new BitmapByteQRCode(qrCodeData))
                    {
                        var qrCodeAsByteArray = qrCode.GetGraphic(20, "#FF0000", "#FFFFFF");
                        return File(qrCodeAsByteArray, "image/bmp");
                    }
                }
            }
        }

Your Environment

codebude commented 5 years ago

Fixed in https://github.com/codebude/QRCoder/pull/148