c# - 无法在运行 Mono 的 Mac OSX 上以 C# 加载 PNG

标签 c# macos mono bitmap png

在 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 文件都会发生这种情况;只有这个。
alt text

除非我切换到 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/

相关文章:

c# - MONO 4.6.2 服务器 CPU 使用率高

c# - Mono GC max-heap-size 没有记录。在生产中使用安全吗?

objective-c - 查找可用的 USB 设备 Mac OS X

objective-c - 创建一个没有 Nib 的自定义 NSViewController

macos - Mac OS X 的 Spotlight 可以配置为忽略某些文件类型吗?

c# - 'Debug.Assert' 语句在 Mono 中不起作用

c# - MVVM、ObservableCollection 和 Reactive Extensions (Rx) 的跨线程访问无效

c# - SqlDataReader 已经在不同的命令中打开

c# - 文本框选择颜色和选择括号颜色

c# - WPF - 具有多重绑定(bind)的工具提示