有没有一个.NET库可以用来以编程方式生成我自己的GIF图像?
至少,我希望逐个像素地构建它。最好是支持文本和形状。
这是我想要做的一个例子。我在Photoshop…里模拟的
Number line graphic http://img143.imageshack.us/img143/5458/dollarlineot9.gif
你有什么建议吗?
发布于 2008-12-08 18:28:12
Bitmap bmp = new Bitmap(xSize, ySize, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bmp)) {
// Use g and/or bmp to set pixels, draw lines, show text, etc...
}
bmp.Save(filename, ImageFormat.Gif);任务完成
发布于 2008-12-08 18:33:21
请注意,除了bmp.Save(filename, ImageFormat.Gif);方法之外,还有一个bmp.Save(stream, ImageFormat.Gif);,它允许您创建图像并将其输出到网页,而无需将其保存到服务器硬盘中。
发布于 2008-12-08 18:37:06
下面是使用System.Drawing名称空间中的类执行此操作的开始。它绘制了一条带有两个框的线条,以演示对形状的支持,而不是简单地设置像素。
// add a reference to System.Drawing.dll
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap(400, 100);
using (Graphics g = Graphics.FromImage(bmp))
{
g.FillRectangle(Brushes.White, 0.0f, 0.0f, 400f, 100f);
// draw line
using (Pen p = new Pen(Color.Black, 1.0f))
{
g.DrawLine(p, 0, 49, 399, 49);
}
// Draw boxes at start and end
g.FillRectangle(Brushes.Blue, 0, 47, 5, 5);
g.FillRectangle(Brushes.Blue, 394, 47, 5, 5);
}
bmp.Save("test.gif", ImageFormat.Gif);
bmp.Dispose();
}
}
}https://stackoverflow.com/questions/350354
复制相似问题