Description
Discussed in #487
Originally posted by VladdyH March 25, 2024
Hi, successfully implemented generating QR code that provides users with vCard information, but only when there are no diacritics.
I implemented QRCoder nuget v. 1.4.3 within my .NET Framework 4.8 web application that is set to use utf-8 by proper meta tag: <meta charset="utf-8" />
in the pages.
The case:
When I try to use czech characters - e.g.:
BEGIN:VCARD
VERSION:3.0
N:Novák;Janěščřžýáíé;
FN:Mgr. & Mgr. Janěščřžýáíé Novák, DiS.
ORG:MyCompany
TITLE:Mgr. & Mgr.
TEL;TYPE=,VOICE:+420123456789
ADR;TYPE=:;;
EMAIL:testovaci@adresa.tst
END:VCARD
Then the information read by QR scanner does not show the ěščř... characters correctly - only shows ??? and another garbage.
But when I add "úů" characters to the N... line:
BEGIN:VCARD
VERSION:3.0
N:Novák;Janěščřžýáíéúů;
FN:Mgr. & Mgr. Janěščřžýáíéúů Novák, DiS.
ORG:MyCompany
TITLE:Mgr. & Mgr.
TEL;TYPE=,VOICE:+420123456789
ADR;TYPE=:;;
EMAIL:testovaci@adresa.tst
END:VCARD
Then the information read by QR scanner shows every character correctly.
Any elaboration about using another version of vCard (e.g. 2.1) + specifying "N;CHARSET=UTF-8:Novák;Janěščřžýáíéúů;" did not give any effort.
My implementation for the code generation is pretty straightforward and works, except the case described above:
public byte[] GetQRCode(string vstup, Color barvaKostek)
{
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
{
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(vstup, QRCodeGenerator.ECCLevel.L))
//ECCLevel = ErrorCorrectionLevel - odolnost proti chybám čtení (L=7%, M=15%, Q=25%, H=30%
{
using (QRCode qrCode = new QRCode(qrCodeData))
{
Bitmap qrCodeImage = qrCode.GetGraphic(2, barvaKostek, Color.White, true);
// číselný parametr pro GetGraphic = počet pixelů, které obsadí 1 zobrazený černý bod v grafickém výstupu
using (var ms = new MemoryStream())
{
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.GetBuffer();
}
}
}
}
}
Am I missing anything that I should set for the QRCoder to work properly even without the "úů" characters?