在C#Windows phone 8.1中生成.vcf卡/名片的二维码

问题描述 投票:0回答:1

我创建了一张VCard /名片。我需要从该Vcard创建QR码。当用户扫描然后QR码然后显示选项以将该vcard保存在联系人列表中。我能够从字符串生成QR码,但我不知道如何生成StorageFile / Vcard的QR码。

这是我的代码。

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        vcard = e.Parameter as StorageFile;



        IBarcodeWriter writer = new BarcodeWriter
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new ZXing.Common.EncodingOptions
            {
                Height = 300,
                Width = 300
            }
        };


        var result2 = vcard;

     //  Result2 contain vcard. but writer.Write()   need string formate.

       // below commented line display error. because result2 is not string 
       // var result = writer.Write(result2);


        var result = writer.Write(result2.ToString());


        var wb = result.ToBitmap() as WriteableBitmap;

        //add to image component
        bar_image.Source = wb;
  }

enter image description here

c# windows-phone-8.1 windows-store-apps qr-code vcard
1个回答
0
投票

请在GitHub上看这个项目:QrCoder

根据项目的Wiki,可以为vCard生成QR码和其他一些要求。对于vCards,QrCoder只需要大约6行代码:

- 从Wiki逐字复制:

ContactData generator = new ContactData(ContactData.ContactOutputType.VCard3, "John", "Doe");
string payload = generator.ToString();


QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
var qrCodeAsBitmap = qrCode.GetGraphic(20);
© www.soinside.com 2019 - 2024. All rights reserved.