我正在尝试将某些.png文件直接打印到打印机。
因此,我设置了此功能:
private void Print(string filepath)
{
LocalPrintServer printServer = new LocalPrintServer();
PrintQueue printQueue = printServer.GetPrintQueue("PDFCreator");
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(filepath);
image.EndInit();
PrintDialog printDialog = new PrintDialog
{
PrintQueue = printQueue
};
DrawingVisual visual = new DrawingVisual();
var dc = visual.RenderOpen();
dc.DrawImage(image, new System.Windows.Rect { Width = image.Width, Height = image.Height });
printDialog.PrintVisual(visual, filepath);
}
打印本身可以正常工作,但是仅打印一张空白纸。