c# - 在 Ubuntu 中没有可用于格式 GIF 的编解码器

标签 c# .net ubuntu mono codec

这是我从中得到的错误

8/27/2013 5:37:36 AM

Function Name : CreateCheckCodeImage 

Message : No codec available for format:b96b3cb0-0728-11d3-9d7b-0000f81ef32e

这是 CreateCheckCodeImage 函数的源代码

private void CreateCheckCodeImage(string checkCode)
    {
        if (checkCode == null || checkCode.Trim() == string.Empty)
        {
            return;
        }
        Bitmap bitmap = new Bitmap((int)Math.Ceiling((double)checkCode.Length * 12.5), 22);
        Graphics graphic = Graphics.FromImage(bitmap);
        try
        {
            Random random = new Random();
            graphic.Clear(Color.White);
            for (int i = 0; i < 25; i++)
            {
                int num = random.Next(bitmap.Width);
                int num1 = random.Next(bitmap.Width);
                int num2 = random.Next(bitmap.Height);
                int num3 = random.Next(bitmap.Height);
                graphic.DrawLine(new Pen(Color.Silver), num, num2, num1, num3);

                Font font = new Font("Arial", 12f, FontStyle.Bold | FontStyle.Italic);
                LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, bitmap.Width, bitmap.Height), Color.Blue, Color.DarkRed, 1.2f, true);
                graphic.DrawString(checkCode, font, linearGradientBrush, 2f, 2f);
                for (int j = 0; j < 100; j++)
                {
                    int num4 = random.Next(bitmap.Width);
                    int num5 = random.Next(bitmap.Height);
                    bitmap.SetPixel(num4, num5, Color.FromArgb(random.Next()));
                }
                graphic.DrawRectangle(new Pen(Color.Silver), 0, 0, bitmap.Width - 1, bitmap.Height - 1);
                MemoryStream memoryStream = new MemoryStream();
                bitmap.Save(memoryStream, ImageFormat.Gif);
                base.Response.ClearContent();
                base.Response.ContentType = "image/Gif";
                base.Response.BinaryWrite(memoryStream.ToArray());
            }
        }
        catch (Exception exception)
        {
            CY.WriteError(CY.GetCurrentMethod(), exception.Message);
        }
        finally
        {
            graphic.Dispose();
            bitmap.Dispose();
        }
    }

我发现代码问题是在保存状态。

bitmap.Save(memoryStream, ImageFormat.Gif);
base.Response.ClearContent();
base.Response.ContentType = "image/Gif";
base.Response.BinaryWrite(memoryStream.ToArray());

我使用的是 Ubuntu 12.04,我已经安装了 GDI+ 和 gif ext。

root@cy-VirtualBox:~/WebSite2# dpkg --get-selections | grep gif
libgif-dev                  install
libgif4                     install
root@cy-VirtualBox:~/WebSite2# dpkg --get-selections | grep jpeg
libjpeg-turbo8                  install
libjpeg8                    install
root@cy-VirtualBox:~/WebSite2# dpkg --get-selections | grep gdi
printer-driver-sag-gdi              install
root@cy-VirtualBox:~/WebSite2# 

如何解决这个问题?它在我的带有 IIS 的 Windows XP 中运行良好,但在 Ubuntu 和 Mono 中运行不正常。
p/s: 我可以确定该文件是 gif 文件。因为在 IIS 上运行良好

这是我使用 gdk-pixbuf-query-loaders 检查 ubuntu 命令

"/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-gif.so"
"gif" 4 "gdk-pixbuf" "The GIF image format" "LGPL"
"image/gif" ""
"gif" ""
"GIF8" "" 100

如何在Ubuntu中安装GIF解码器?

最佳答案

通过更改代码解决了问题

 public static byte[] ImageToByte(Image img)
    {
        ImageConverter converter = new ImageConverter();
        return (byte[])converter.ConvertTo(img, typeof(byte[]));
    }

byte[] trytry = ImageToByte(bitmap);
                memoryStream.Write(trytry,0,trytry.Length );
                base.Response.ClearContent();
                base.Response.ContentType = "image/Gif";
                base.Response.BinaryWrite(memoryStream.ToArray());

不再使用位图来保存文件。所以我们不需要编解码器。无论如何,有人知道如何在 Ubuntu 中安装 GIF 编解码器吗?

关于c# - 在 Ubuntu 中没有可用于格式 GIF 的编解码器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18453695/

相关文章:

c# - .net Winforms 中的保存图像问题

c# - 检测 DataContext 表或 View 是否存在的快速方法

.net - .Net:空字符串不是空格字符吗?

ubuntu - 在 Ubuntu 中停止可执行 JAR 的 Shell 脚本

c - 查找数字阶乘中的尾随 0

c# - 挣扎于最小起订量 : The following setups were not matched

c# - MonoDroid、MonoTouch 通用 UI

c# - 编译时的目标平台/处理器

c# - .NET 的缩略图库

c# - 无法启动带有 mod_mono 的 apache2。错误 : undefined symbol: unixd_config