views:

225

answers:

1

I want to draw one picture over another and dump it to HttpResponse. My code looks like this:

//file name points to a gif image
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(filename);
System.Drawing.Image smallImage = System.Drawing.Image.FromFile(smallFilename);

using(Bitmap tempImage = new Bitmap(originalImage))
{
    Graphics graphics = Graphics.FromImage(tempImage);
    PointF ulCorner = new PointF(10.0F, 10.0F);
    graphics.DrawImage(windfarmImage, ulCorner);
}

tempImage.Save(Response.OutputStream, ImageFormat.Gif);

If I change last line to

tempImage.Save(Response.OutputStream, ImageFormat.Jpeg);

it fixes the problem. But I have to have png as a result. Can I somehow keep palette from original file? Original file is gif, so it should be possible to have gif as a result without loosing any colors I guess.

+1  A: 

If the source images have a large number of colours, then saving the file as a Gif may cause some dithering as the palette size is reduced to 256 colours.

Is it a requirement to save the file as a Gif, or could a different format be tried (such as Jpeg or Png)?

Tim Greaves
original file is gif and I have to keep it this way
Georgy Bolyuba