Resizing a transparent image adds gray background

O

Oleg Ogurok

Hi all,

I'm having this problem. I have a 50x50 GIF image with a transparent
background. I'm trying to resize it to 25x25 using GDI+ capabilities.
With Windows Forms' Image control, the image shows fine. However, when I try
to stream the image into a browser in a ASP.NET application, the background
that's supposed to be transparent looks grayish.

Here's my codebehind:

private void Page_Load(object sender, System.EventArgs e)
{
Stream stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("WebStaging.Img.gif");
// read the file from assembly
Image img = Image.FromStream(stream);
img = new Bitmap(img, 25, 25); // resize to 25x25
string contentType = "image/png";
MemoryStream memStream = new MemoryStream();
img.Save(memStream, ImageFormat.Png);
byte[] rawBytes = memStream.ToArray();
Response.ContentType = contentType;
Response.BinaryWrite(rawBytes);
Response.End();
}

I've tried streaming the file as GIF, the background becomes even darker.
Any suggestions are welcome.

Thanks,
-Oleg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top