首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net 网页,小弟我这样画直线如何不显示呢

2012-04-12 
asp.net 网页,我这样画直线怎么不显示呢代码是这样写的Bitmap img new Bitmap(600, 400)Graphics g G

asp.net 网页,我这样画直线怎么不显示呢
代码是这样写的
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;        }    }} 

热点排行