Skip to content

vCard to QRCoder - diacritics problem #554

Closed
@VladdyH

Description

@VladdyH

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?

After I placed text with diacritics to "ORG:" value, all my readers can correctly read all diacritics from QR code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions