我正在成功構建 .NET Core 3.1 WPF 應用程式!但是當我運行一個使用 System.Drawing 的自定義列印函式時,它會拋出這個錯誤:
Exception thrown: 'System.IO.FileNotFoundException' in System.Drawing.Common.dll
我什至嘗試通過 NuGet 安裝:

應用程式正在成功構建,但是當我嘗試運行列印功能時,它會拋出錯誤并列印空白頁。
有趣的是相同的代碼正在與控制臺應用程式一起使用
以下是有關控制臺應用程式的詳細資訊


相同版本的 System.Drawing.Common 也不起作用
##代碼列印功能>>
public static void Print()
{
PrintDocument p = new PrintDocument();
p.PrintPage = delegate (object sender1, PrintPageEventArgs e1)
{
graphics = e1.Graphics;
Bitmap logo = (Bitmap)Bitmap.FromFile(path, false);
graphics.DrawImage(logo, new Point(25, (int)Offset));
layout = new RectangleF(new PointF(startX 75, startY Offset 25), layoutSize);
graphics.DrawString("Receipt", font10, brush, layout, formatCenter);
};
try
{
p.Print();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occured While Printing \n" ex);
}
}
uj5u.com熱心網友回復:
您遇到的問題path是找不到 in WPF 版本,請參閱
Bitmap.FromFile(path, false),
不是 System.Drawing.Common.dll 的問題
確保有一個path.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/382347.html
上一篇:如何在Chrome中通過nativeMessaging發送/接收短信?
下一篇:如何繪制模擬心電圖?
