Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logo insert after QRCode unable to scan #397

Closed
supun151515 opened this issue May 5, 2022 · 7 comments · May be fixed by #407
Closed

Logo insert after QRCode unable to scan #397

supun151515 opened this issue May 5, 2022 · 7 comments · May be fixed by #407

Comments

@supun151515
Copy link

I have added a non-transparent Bitmap as a logo. Then I am not able to scan the QRCode. I guess, because of the center logo, some of the QRCode pixels are hidden.

Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile("C:\myimage.png"));

[Here is the link for logo, QrCode with Logo and without logo]
(https://drive.google.com/drive/folders/120zZPzvk_A-64r3As_NIEpom3j5BuYli?usp=sharing)

Cheers,
Supun

@technos12
Copy link

technos12 commented May 5, 2022 via email

@supun151515
Copy link
Author

Hi,
Can you suggest a code for me for that?

@technos12
Copy link

technos12 commented May 5, 2022

To be able to set this parameter, you have to add before your line of code :

QRCodeGenerator qrGenerator = new QRCodeGenerator();
//This is where we set the ECCLevel
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile("C:\myimage.png"));

The ECCLevel can be set to 4 levels :
public enum ECCLevel
{
L, // 7% may be lost before recovery is not possible
M, // 15% may be lost before recovery is not possible
Q, // 25% may be lost before recovery is not possible
H // 30% may be lost before recovery is not possible
}

Hope you have your solution to make it work now :)

@supun151515
Copy link
Author

supun151515 commented May 5, 2022

Hi,
Thanks for the reply. I used the same code as below. It doesn't scan the QR code.

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("This can be a url link to somewhere", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (var ms = new MemoryStream())
   {
       using (var bitmap = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile("C:\mygivenLogo.png"), 80))
         {
             bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
             return Convert.ToBase64String(ms.GetBuffer());
         }
    }

@technos12
Copy link

Ok, I checked your image examples. I think the image is too big, especially too wide. In the examples you can find online, only a small square in the center is used for a logo, so try to reduce the size of the image, and it may work.
Technically, by putting your image wide like that, you are overlapping areas that are used to "find and decode" the qrcode, so the system is lost.
Hope you find your way with that.

@supun151515
Copy link
Author

Hi,
Thanks for the reply. Let me try with smaller logo and see

@codebude
Copy link
Owner

codebude commented Apr 23, 2024

Since there was no further feedback, I will close the issue. If you need further help @supun151515 , just let me know and open the issue again.

As already noted by @technos12, the logo is simply too large. A QR code may only be covered by a maximum of X percent until it can no longer be read. As already mentioned, the X in X percent can be determined by the ECC (error correction) level. When working with logos, the highest possible ECC level, i.e. H, should always be selected.

If, as in your case, the QR code is still not readable, the logo must be reduced in size. The iconSizePercent parameter can be used for this. (https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers#parameter-table) Reduce the parameter to make the logo smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants