【问题标题】:Cannot load PNG in C# on Mac OSX running Mono无法在运行 Mono 的 Mac OSX 上的 C# 中加载 PNG
【发布时间】:2011-06-08 03:35:18
【问题描述】:

在 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 上运行良好。

【问题讨论】:

    标签: c# macos mono bitmap png


    【解决方案1】:

    我尝试在我的 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)  
    

    错误

    不支持 48bpp 的 PNG 图像 通过 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 上没有导致错误。

    希望这会有所帮助,问候

    【讨论】:

    • 谢谢谢尔盖。由于我的目标平台是 Mac 和 Windows,我决定只在这段代码周围添加一个 try-catch 块,并告诉艺术家更改这些图像的位深度。
    【解决方案2】:

    您是否检查过是否有任何 MacOS X 应用程序可以查看图像(可能使用 libpng)?

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多