views:

240

answers:

2

Hi,

I've got a series of GIFs that I need to crop on the fly, I'm using a HTTP Handler in C# so I can better encapsulate the code - provide caching for the result etc.

Currently, when I draw the existing image to a new Image via the Graphics object all the transparency is lost.

I've tried various techniques to try and maintain the transparency, but to no avail.

Things I've tried:

  • Using the MakeTransparent (Color) method call
  • Using the ImageAttriutes with a combination of ColorMap and SetColorKey

I don't really want to start using unsafe operators or Win32 calls.

Any ideas?

A: 

When I have used transparency I've always used Bitmap. I.e.

System.Drawing.Image SourceImage = System.Drawing.Image.FromFile("the.gif");
System.Drawing.Bitmap NewImage = new System.Drawing.Bitmap(SourceImage);
// Do Processing
NewImage.MakeTransparent();
// Store changes
NewImage.Save(..., System.Drawing.Imaging.ImageFormat.Png);

Of course if you cannot move away from the Graphics object then that may not be of much use.

Ash
+2  A: 

This seems to have been answered already http://stackoverflow.com/questions/189392/how-do-you-draw-transparent-image-using-systemdrawing

duckworth