侃侃无极
public class MonthlyReportHanlder : IHttpHandler { #region IHttpHandler Members public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.BufferOutput = false; string year = context.Request["Year"]; string kpi1 = context.Request["kpi1"]; string kpi2 = context.Request["kpi2"]; var entities = new YearReport().GetData(year); var image = this.GenerateImage(entities, kpi1, kpi2); image.Save(context.Response.OutputStream, ImageFormat.Jpeg); image.Dispose(); } #endregion private Image GenerateImage(IList<YearEntity> entities, string kpi1, string kpi2) { Image image = new Bitmap(w, h, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(image); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); g.FillRectangle(b, rect); g.DrawRectangle(p, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1)); g.Dispose(); return image; } }这是我在ASP.NET项目中动态生成图片的代码,为了看清结构,我把一些无关的代码删除了,你将就着参考下吧