QRCoder
QRCoder copied to clipboard
Logo insert after QRCode unable to scan
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
You should increase the quality of the qrcode, to have more repetition of the data in the code. This is going to help if you then hide some of it with an image. Good try.
Le jeu. 5 mai 2022 à 05:59, Supun Silva @.***> a écrit :
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
— Reply to this email directly, view it on GitHub https://github.com/codebude/QRCoder/issues/397, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEC4VMVM52JU7MXO6D5XTKDVINBRPANCNFSM5VD25RAQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hi, Can you suggest a code for me for that?
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 :)
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());
}
}
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.
Hi, Thanks for the reply. Let me try with smaller logo and see
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.