在 C# 中,我尝试使用最新的 Mono 在 Mac OSX 上加载一个 png 文件
using System.Drawing;
Bitmap bmp = new Bitmap("test.png");
出现以下错误
Either the image format is unknown or you don't have the required libraries to decode this format [GDI+ status: UnknownImageFormat]
并非所有 png 文件都会发生这种情况;只有这个。
除非我切换到 8bpp,否则在 photo shop 中重新保存并不能解决问题。我需要安装什么来支持这个“特殊”的 png 文件吗?在 Windows 上运行良好。
最佳答案
我尝试在我的 ubuntu 上用 mono 加载这个文件,但出现以下异常:
** (mono_load_bitmap:3490): WARNING **: PNG images with 48bpp aren't supported by libgdiplus.
Either the image format is unknown or you don't have the required libraries to decode this format [GDI+ status: UnknownImageFormat]
at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.String filename, Boolean useIcm) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.String filename) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (string)
错误
PNG images with 48bpp aren't supported by libgdiplus
似乎与您在 Mac 上使用的具有相同的性质。快速谷歌搜索没有返回任何关于如何修复它的信息。我的建议是尝试用 Gdk.Pixbuf 打开它。类:
Gdk.Pixbuf pic = new Gdk.Pixbuf("test.png");
// shows pixbuf in the Gtk.Image widget
Gtk.Image image = new Gtk.Image();
image.Pixbuf = pic;
此调用在我的 ubuntu 上没有导致错误。
希望这对你有帮助,问候
关于c# - 无法在运行 Mono 的 Mac OSX 上以 C# 加载 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4674453/