在网页中动态的生成一个gif图片

大家知道股票网站的k线图是动态生成的定时刷新php 就有动态生成图片的功能
那么怎样用asp.net在网页中动态的生成一个图片呢?
下面我要举的例子是动态的生成一个图片显示当前时间
namespace zsq
{
using System;
using System.Drawing;
using System.Web.UI;

public class mytempimage : page
{
public string createimage()
{
string str=datetime.now.tostring();
bitmap image=new bitmap(200,30);
graphics g=graphics.fromimage(image);
string thefullname=server.mappath("/")+"\\nowtime.gif";
g.clear(color.white);
g.drawstring(str,new font("courier new", 10),new solidbrush(color.red),20,5);
//graphics 类还有很多绘图方法可以绘制 直线、曲线、圆等等
image.save(thefullname,system.drawing.imaging.imageformat.gif);
return "/nowtime.gif";
}
}
}

调用时
void page_load(object sender,eventargs e)
{
mytempimage mytempimage=new mytempimage();
img1.src=mytempimage.createimage();
}

本篇文章来源于 dotnet开源社区  原文链接:http://www.openaspx.com/article/201106/16/20110616051849.htm

posted on 2011-06-16 17:21  IT凡人  阅读(280)  评论(0)    收藏  举报

导航