Unity使用System.Drawing.dll在Mac上报异常DllNotFoundException: gdiplus.dll

在Unity中使用Mono库System.Drawing.dll处理图像,Windows上一切正常,在Mac上运行报异常:

DllNotFoundException: gdiplus.dll
System.Drawing.GDIPlus..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus
System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelFormat format)
System.Drawing.Bitmap..ctor (Int32 width, Int32 height)
(wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (int,int)

System.Drawing.dll内部依赖于gdiplus.dll,gdiplus.dll在Window上属于系统自带库所以一切正常。Mac上不存在gdiplus.dll,也未在网上找到独立的Mono版gidplus.dll。
但在Unity和MonoDevelop安装路径下有个libgdiplus.dylib,倒腾到dllmap中依旧异常,这两个路径下带的libgdiplus.dylib都不能正常使用。
最后安装了完整的Mono环境才搞定,Unity自带的Mono运行时是经过定制的这也能理解。

解决步骤如下:

  1. 下载OSX版Mono(http://www.mono-project.com/download/#download-mac)并安装;
  2. 打开文件Application/Unity/Unity.app/Contents/Frameworks/Mono/etc/mono/config;
  3. 增加如下内容(具休路径以第1步安装mono版本而定):
    <dllmap dll="gdiplus" target="/Library/Frameworks/Mono.framework/Versions/4.0.4/lib/libgdiplus.dylib" />
    <dllmap dll="gdiplus.dll" target="/Library/Frameworks/Mono.framework/Versions/4.0.4/lib/libgdiplus.dylib" />

转载请注明:兜里-http://blog.dou.li/DllNotFoundException-gdiplus-dll.html

标签:unity3d, mono, mac

添加新评论