1

我保存图像但在 GDI 中出现错误 + 发生一般错误。如何摆脱错误?

 public void save_all_image(string path_directory)
    {
        for (int i = 0; i < list_real_foto.Count; i++)
        {
            string format = list_format_file[i].ToLower();
            list_real_foto[i].Save(path_directory + "\\" + i.ToString() + "." + format);//In GDI + generic error occurred
        }
    }
4

1 回答 1

0

当涉及到错误消息时,GDI+ 几乎是最糟糕的。在您的情况下,我要做的是检查您是否将其保存到正确的路径,然后确保您有权将文件保存在那里。

您还应该避免连接字符串来构建路径,在System.IO.Path中有一个很棒的辅助类可用,称为Combine()。您可能还想考虑使用string.Format()使代码更易于阅读。

list_real_foto[i].Save(System.IO.Path.Combine(path_directory, string.Format("{0}.{1}", i, format));
于 2013-08-21T08:20:27.367 回答