【问题标题】:Exception thrown: 'System.IO.FileNotFoundException' in System.Drawing.Common.dll抛出异常:System.Drawing.Common.dll 中的“System.IO.FileNotFoundException”
【发布时间】:2022-01-18 12:53:34
【问题描述】:

我正在成功构建一个 .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);
            }
        }

【问题讨论】:

  • 如果在两种情况下都使用相同版本的 System.Drawing.Common,问题是否存在?
  • 我试过同样的版本也不能用
  • 你能提供你的代码吗?
  • @Llama 添加了代码...

标签: c# wpf


【解决方案1】:

你遇到的问题是找不到WPF版本的path,见

Bitmap.FromFile(path, false),

不是 System.Drawing.Common.dll 的问题

确保有path 的文件。

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 2021-09-17
    • 2014-12-05
    • 2013-05-24
    • 2012-01-24
    相关资源
    最近更新 更多