Kieron
Kieron

Reputation: 27127

How do I maintain transparency in an image from a Http Handler when using Graphics.DrawImage?

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:

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

Any ideas?

Upvotes: 1

Views: 934

Answers (2)

John Lemp
John Lemp

Reputation: 5067

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

Upvotes: 2

Ash
Ash

Reputation: 5087

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.

Upvotes: 0

Related Questions