question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QR Codes with images losing data when converting to byte[]

See original GitHub issue

Type of issue

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

Expected Behavior

I expect the generated QR code to look like this but have the logo in the middle. Screen Shot 2020-04-07 at 1 23 27 PM

Current Behavior

This is currently what is output if adding a logo. Screen Shot 2020-04-07 at 1 23 03 PM

Steps to Reproduce (for bugs)

Here is my code for generating a QR Code with a logo

private async Task<byte[]> GetLogoQRCode(string url, string darkColorHex, string logoUrl)
        {
            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 QRCode(qrCodeData))
            using (var stream = new MemoryStream())
            {
                // Grab an image from the internet and convert it to a Bitmap
                var logo = await _webHelper.GetImageFromWeb(logoUrl);
                // Convert a Hex string into a Color
                var darkColor = ColorTranslator.FromHtml(darkColorHex);
                var qrCodeImage = qrCode.GetGraphic(20, darkColor, Color.White, logo, 20);
                qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                var result = stream.ToArray();
                return result;
            }
        }

Your Environment

  • OS: macOS Mojave Version 10.14.6
  • Version used: 1.3.5
  • Compiled from source or NuGet package?: Nuget
  • Payload/Encoded text: payload
  • Used payload generator: yes
  • Used ECC-level:
  • Used renderer class:
  • Environment (.NET 3.5, .NET 4.X, .NETCore, …): .NET 2.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
codebudecommented, Nov 16, 2020

Hi @Sdraugel , @manikata0 , @Simon311 @johnboker , @abrari - thanks for you support and pushing me again and again to merge this. I really apologize for the long response times. That’s not how it should work out usually. Thus thanks again for being patient! 😃

1reaction
abraricommented, Jul 2, 2020

Waiting this fix to be released to nuget

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storing binary data in QR codes
I used System.Convert.ToBase64String to convert the supplied sample byte array into a Base64-encoded string, then I used ZXing to create a ...
Read more >
Decoding a Broken QR Code
A QR code's data is layed out in a very particular manner which means that ... I recommend converting each byte you read...
Read more >
Transfer Data with Animated QR codes
The article talks about how to transfer data with animated QR codes.
Read more >
QR Code Size: Minimum Size, Maximum Size & More [2023]
A QR code is capable of encoding a maximum of 2953 bytes of data, ... such as brand logos & images, graphics, shapes,...
Read more >
Color Can Triple QR Code Capacity
There are quite a few variations of rMQR, but the largest can hold 361 bytes. The basic idea is to generate three different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found