2013-05-06 71 views
0

我正在WPF中創建一個銷售點系統。我想在訂單完成時打印發票。數據將從發票的文本框中提供:txtinvoicestxtQty,txtTotalPrice,txtAmountPaidtxtDate是我想在發票上打印的一些文本框。還有一個條形碼圖像以及打印在發票上所需的每個訂單。如何從WPF控件打印發票

我能夠使用流程文檔打印所有內容。但是我無法打印此條形碼圖像。

//InvoiceID Generate 
txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd" + userId); 
//Barcode Generation 
BarcodeEncoder enc = new BarcodeEncoder(); 
WriteableBitmap image = enc.Encode(BarcodeFormat.Code39, txtInvoiceID.Text); 
barCodeImage.Source = image; 

任何人都可以幫助我在WPF中打印?

回答

0

從我的頭頂,使用下面的代碼(未測試)。

//InvoiceID Generate 
txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd" + userId); 
//Barcode Generation 
BarcodeEncoder enc = new BarcodeEncoder(); 

System.Windows.Controls.Image imgBarCode = new System.Windows.Controls.Image(); 
System.Drawing.Bitmap bm = enc.Encode(BarcodeFormat.Code39, txtInvoiceID.Text); 

using (MemoryStream ms = new MemoryStream()) 
    {    
    bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png); 
    byte[] byteImage = ms.ToArray(); 
    Convert.ToBase64String(byteImage); 
    imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); 
    } 

// do whatever you want with imgBarCode now. 
+0

我不知道爲什麼,但它給我的錯誤 錯誤:無法隱式轉換類型「System.Windows.Media.Imaging.WriteableBitmap」到「System.Drawing.Bitmap」 – 2013-05-06 19:25:40