Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从WPF控件打印发票_Wpf_Image_Barcode Printing - Fatal编程技术网

如何从WPF控件打印发票

如何从WPF控件打印发票,wpf,image,barcode-printing,Wpf,Image,Barcode Printing,我正在WPF中创建一个销售点系统。我想在订单完成时打印发票。数据将从发票文本框中提供:txtinvoices、txtQty、txtTotalPrice、txtAmountPaid和txtDate是我想在发票上打印的一些文本框。对于需要在发票上打印的每个订单,也有一个条形码图像 我能够使用flow文档打印所有内容。但是我无法打印这个条形码图像 //InvoiceID Generate txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd"

我正在WPF中创建一个销售点系统。我想在订单完成时打印发票。数据将从发票文本框中提供:
txtinvoices
txtQty
txtTotalPrice
txtAmountPaid
txtDate
是我想在发票上打印的一些文本框。对于需要在发票上打印的每个订单,也有一个条形码图像

我能够使用flow文档打印所有内容。但是我无法打印这个条形码图像

//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打印吗?

在我的脑海中,使用下面的代码(未经测试)


我不知道为什么,但它给了我错误:无法隐式地将类型“System.Windows.Media.Imaging.WriteableBitmap”转换为“System.Drawing.Bitmap”
//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.