Pergunta

This is what Error i get from

8/27/2013 5:37:36 AM

Function Name : CreateCheckCodeImage 

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

This is CreateCheckCodeImage Function's Source Code

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();
        }
    }

i have found that the code problem are on the saving state.

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

And i m using Ubuntu 12.04 and i have installed GDI+ and 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# 

How to solve this problem? it is work fine in my window XP with IIS, but not in Ubuntu and Mono.
p/s: i can sure that file is gif file. because on IIS are working fine

and this is i checking on ubuntu command with gdk-pixbuf-query-loaders

"/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

How to install GIF Codec in Ubuntu?

Foi útil?

Solução

Problem solved with changing the code with

 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());

No more using bitmap to save the file. so we don't need the codec. Anyway, anyone know how to install GIF codec in Ubuntu?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top