这就是我得到的错误
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 上工作正常
这是我检查 ubuntu 命令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