我在寫一個新的WPF應用程序,它創建一些可視元素,然後嘗試在Poloroid打印機上打印它們。我成功地打印使用WPF的System.Printing類如下:WPF使用Magstrip編碼打印到打印機
Dim Pd As PrintDialog = New PrintDialog()
Dim Ps = New LocalPrintServer()
Dim PrintQueue = New PrintQueue(Ps, "Poloroid Printer")
Pd.PrintQueue = PrintQueue
Pd.PrintVisual(Me.Grid1, "Print Job 1") 'this prints out perfectly
的問題是,poloroid打印機,您可以使用寫入Magstrip在卡背面的SDK。我有一個使用System.Drawing.Printing中的PrintPageEventArgs的工作示例,但是我找不到WPF世界的任何近似匹配。下面是該代碼:
Private Sub PrintPage(ByVal sender as Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
'...
' Obtain the device context for this printer
deviceContext = e.Graphics.GetHdc().ToInt32()
'... device context is used in SDK to write to magstrip
e.Graphics.ReleaseHdc(New IntPtr(deviceContext))
End Sub
所以,我的問題是:
如何打印使用System.Drawing.Printing
OR
我現有的標記(XAML)是否有在System.Printing
事件與SDK交談並獲取Int32
deviceContext?
,我試圖RenderTargetBitmap
類呈現視覺WPF中位圖和轉換位圖System.Drawing.Bitmap
RenderTargetBitmap bitmapSource;
...
bitmapSource.Render(visual);
...
using(MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapSource));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
...
}
但印刷不清晰,完美。
相關:http:// stackoverflow。COM /問題/ 4544035/ID卡,磁條編碼 – naveen 2011-01-12 12:29:58