2016-06-13 165 views
2

我試圖安裝QrCode.net金塊包的UWP應用程序,但它對於我寫的錯誤:如何在UWP應用程序中生成QR碼?

using System.Drawing; 
using System.Drawing.Imaging; 
using System.Windows.Forms; 

不存在沒有。

有誰知道任何UWP應用程序的塊金包,可以幫助我創建並顯示從字符串生成的QR碼? (UWP/C#)

回答

5

有沒有人知道任何UWP應用程序的塊金包,可以幫助我創建和顯示從字符串生成的QR碼? (UWP/C#)

由於您正在開發UWP應用程序,因此可以使用Zxing.Net.Mobile軟件包。安裝了這個包後,生成條形碼,你可以參考下面的例子:

<Image x:Name="qrcodeImg" Stretch="None" /> 

後面的代碼:

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    var write = new BarcodeWriter(); 
    write.Format = ZXing.BarcodeFormat.QR_CODE; 
    var wb = write.Write("BarCode Content"); 
    this.qrcodeImg.Source = wb; 
} 
+0

我也嘗試這種做法,但在最後一行我沒有得到錯誤'無法隱式轉換類型「字節[]」到「Windows.UI.Xaml.Media.ImageSource'' –

+0

你可能應該把它'var wb =(寫爲ZXing.BarcodeWriterGeneric )。Write(jsonItem);' – AbsoluteSith

0

這是你如何使用基於MVVM模式格雷斯鋒的做法

XAML

<Image Source="{Binding QRImage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> 

視圖模型

// Property 
public WriteableBitmap QRImage { get; set; } 

// Function to call 
private void SetQR() 
{ 
    var options = new QrCodeEncodingOptions() 
    { 
     DisableECI = true, 
     CharacterSet = "UTF-8", 
     Width = 1000, 
     Height = 1000 
    }; 

    BarcodeWriter writer = new BarcodeWriter(); 
    writer.Format = BarcodeFormat.QR_CODE; 
    writer.Options = options; 
    QRImage= writer.Write(SelectedEvent.GetQrString()); 
}