Ubuntu中没有可用于GIF格式的编解码器

本文关键字:GIF 格式 编解码器 用于 Ubuntu | 更新日期: 2023-09-27 18:29:16

这就是我从得到的错误

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# 

如何解决这个问题?它在我的windows XP和IIS中运行良好,但在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编解码器

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编解码器吗?