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.

4

1 回答 1

1

如果源图像具有大量颜色,则将文件保存为 Gif 可能会导致一些抖动,因为调色板大小减少到 256 种颜色。

是否需要将文件另存为 Gif,或者可以尝试不同的格式(例如 Jpeg 或 Png)?

于 2009-09-09T14:49:32.803 回答