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

时间:2013-08-26 21:55:56

标签: 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的窗口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编解码器?

1 个答案:

答案 0 :(得分:0)

使用

更改代码解决了问题
 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编解码器?