我有一个包含这一行的简单 C# 应用程序:
var mImage = System.Drawing.Image.FromFile(filename);
在 Windows (.NET) 上运行此代码时,图像会正确加载。 在 OS X (Mono) 上运行相同的代码时,应用程序会挂起。调试器永远留在那个调用中。无一异常(exception)。
调用堆栈显示应用程序挂起于:
System.Drawing.GDIPlus.GdiplusStartup ()
这里会出什么问题?
PS:我安装了最新版本的 Xamarin Studio 和 Mono。
最佳答案
1) 不仅要检查您是否拥有最新的 Xamarin Studio 版本,还要检查您是否拥有最新版本!!!
错误报告:
这个问题是由 Troy Dawson 使用 Xamarin Studio Version 5.5 (build 198) 报告的,就在一个多月前:https://bugzilla.xamarin.com/show_bug.cgi?id=23444
"With the latest Mono from the alpha release channel, attached project should raise an typenotfound exception when run at:
var image = Image.FromStream(content);
Because GDIPlus can't be initialized or something.
This is similar to another bug I filed where Image.FromStream() takes a very long time to return when Mono is first run."
完全异常:
An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.Exception: GdiplusStartup
解决方案:
在 2014-09-29 报告错误后的第二天,Sadik Ali 确认他可以重现该问题 Comment 1 ,然后 4 天后,Troy Dawson 确认Xamarin Studio 版本 5.5(内部版本 227)修复了该问题 Comment 2 .
2) 如果最新版本仍然失败,我建议您检查限制并确保支持您加载的图像: https://github.com/mono/libgdiplus/blob/master/TODO
关于c# - Image.FromFile() 或 FromStream() 在 GdiplusStartup 上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26894157/