How can I generate GIF images in .NET?

Is there a .NET library that I can use to programmatically generate my own GIF images?

At a minimum, I would like to create it in pixels. Better will support text and shapes.

Here is an example of what I'm trying to do. I mocked it in Photoshop & hellip;

Numeric String http://img143.imageshack.us/img143/5458/dollarlineot9.gif

What do you recommend?

+6
image gif
source share
8 answers
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); 

Task completed

+12
source share

note that in addition to the bmp.Save(filename, ImageFormat.Gif); method bmp.Save(filename, ImageFormat.Gif); there is bmp.Save(stream, ImageFormat.Gif); , which allows you to create and display an image on a web page without saving it to your server’s hard drive.

+4
source share

This starts here with the classes in the System.Drawing namespace. He draws a line with two cells to demonstrate support for shapes at a higher level than just setting pixels.

 // 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(); } } } 
+2
source share

Why not just use the System.Drawing namespace? Everything you need should be there.

+1
source share

An example of how to use the HTTPHandler to create an image and send it to a stream (using the image code already posted here).

Using:

 <img src="createChart.ashx?data=1"/> 

the code:

 public class CreateChart : IHttpHandler { public void ProcessRequest(HttpContext context) { string data = context.QueryString["data"]; // Or get it from a POST etc Bitmap image = new Bitmap(xSize, ySize, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(Image)) { // Use g to set pixels, draw lines, show text, etc... } BinaryStream s = new BinaryStream(); image.Save(s, ImageFormat.Gif); context.Response.Clear(); context.Response.ContentType = "image/gif"; context.Response.BinaryWrite(s); context.Response.End(); } public bool IsReusable { get { return false; } } } 
+1
source share

Why not use a chart control instead of trying to generate GIFs? If the requirements are strictly for creating this particular GIF, I think using a chart control offers you more flexibility.

0
source share

I like my company products . You can read / write gifs and create them from solid fabric. This is a free run for desktop applications licensed for servers.

0
source share

Create images on the fly using ASP.NET (February 22, 2002) by Stephen Walter

0
source share

All Articles