仅在调试构建中调用Bitmap.Save(…)时出现ExternalException

本文关键字:ExternalException Save 调试 构建 Bitmap 调用 | 更新日期: 2023-09-27 18:16:53

我使用下面的代码输出我的计算,它应该是一个PNG图片。我不明白为什么在调试运行的最后一行给了我一个System.Runtime.InteropServices.ExternalException。在发布版运行时一切正常。

我在网上发现,当图像被其他部分代码使用时,可能会出现此错误,但在我的情况下,这不是真的。

//using System;
//using System.Drawing;
//using System.Drawing.Imaging;
Bitmap png = new Bitmap(this.xPixels, this.yPixels, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(png);
g.Clear(Color.White);
g.DrawString(currentTime, myFont, mySolidBrush, timeX, timeY, myXTitleFormat);
// write image to file
string path4 = string.Concat(Environment.CurrentDirectory, @"'Output'T1'" + this.fileName + ".png");
png.Save(path4, ImageFormat.Png);

仅在调试构建中调用Bitmap.Save(…)时出现ExternalException

联机帮助提示"图片保存格式错误"。

这也很奇怪,你做的东西与Graphics对象,但保存使用Bitmap。对g的操作对Bitmap有影响吗?

无论在调试模式还是发布模式下,下面的代码都会引发异常:

       {
            Bitmap png = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(png);
            g.Clear(Color.White);
            g.DrawString("dummy", SystemFonts.DefaultFont, Brushes.Beige, RectangleF.FromLTRB(5,5,80,80), StringFormat.GenericDefault);
            // write image to file
            string path4 = @"C:'test.png";
            png.Save(path4, System.Drawing.Imaging.ImageFormat.Png);
        }
相关文章:
  • 没有找到相关文章