Question

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?

Was it helpful?

Solution

This seems to have been answered already How do you Draw Transparent Image using System.Drawing?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top