日期:2014-05-19  浏览次数:20826 次

怎么先清空图片后在写入新的图片内容,请看代码
MemoryStream   s   =   new   MemoryStream();
Image   img   =   Image.FromFile(file);
Graphics   graphics   =   Graphics.FromImage(img);
graphics.SmoothingMode   =   SmoothingMode.HighQuality;
Image   img2   =   Image.FromFile(filename);
Rectangle   rect   =   new   Rectangle(x,   y,   img2.Width,   img2.Height);
ImageAttributes   attr   =   new   ImageAttributes();
graphics.DrawImage(img2,rect,0,0,img2.Width,img2.Height,GraphicsUnit.Pixel,attr);
img.Save(s,   img.RawFormat);
graphics.Dispose();
img.Dispose();
FileStream   fi   =   new   FileStream(file,   FileMode.Open,   FileAccess.ReadWrite);
s.WriteTo(fi);
s.Close();
fi.Close();
这些代码运行结果是在原来图片的基础上加上新的内容,请问怎么先清空后在写入新的内容.谢谢

------解决方案--------------------
填充一个区域可以清除图像
graphics.FillRectangle(Brushes.White, new Rectangle(0, 0, 100, 100));