代码是这样写的
Bitmap img = new Bitmap(600, 400);
Graphics g = Graphics.FromImage(img);
Pen p = new Pen(Color.Blue, 2);//定义了一个蓝色,宽度为的画笔
g.DrawLine(p, 10, 10, 100, 100);//在画板上画直线,起始坐标为(10,10),终点坐标为(100,100)
img.Dispose();
g.Dispose();
p.Dispose();
------解决方案--------------------------------------------------------
加img.save(Reponse.outputsream,imageformat.gif);
------解决方案--------------------------------------------------------
给项目添加“一般处理程序”,如Handler.ashx
- C# code
<%@ WebHandler Language="C#" Class="Handler" %>using System;using System.Web;using System.Drawing;public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { Bitmap img = new Bitmap(600, 400); Graphics g = Graphics.FromImage(img); Pen p = new Pen(Color.Blue, 2);//定义了一个蓝色,宽度为的画笔 g.DrawLine(p, 10, 10, 100, 100);//在画板上画直线,起始坐标为(10,10),终点坐标为(100,100) context.Response.ContentType = "Image/GIF"; context.Response.Clear(); context.Response.BufferOutput = true; img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); img.Dispose(); g.Dispose(); p.Dispose(); } public bool IsReusable { get { return false; } }}