asp.net 程序中怎么使用GDI绘图?

我想在aspx、页面实现图片上传的同时生成一大一小两张图片,生成图片的方法谁知道啊,我找了很多资料都是有关winform的,网页和winform的不太一样,解决不了,该怎么办啊?

qq_遁去的一_1
浏览 586回答 2
2回答

侃侃无极

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