Net来生成gif动画
在网页中动态生成gif图片(ASP.net)
众所周知,股票网站的k线图是动态生成的。PHP定时刷新时,有动态生成图片的功能。
那么如何使用ASP.NET在网页中动态生成图片呢?
下面我要举的例子是动态生成一个图片来显示当前时间。
命名空间Wmj
{
使用系统;
使用系统。绘图;
使用系统。Web . UI
公共类MyTempImage : Page
{
公共字符串CreateImage()
{
字符串str =日期时间。now . ToString();
位图图像=新位图(200,30);
图形g =图形。FromImage(图像);
string thefullname=Server。MapPath("/"+" \ \ now time . gif ";
g.透明(彩色。白色);
g.拉绳(str,新字体(“Courier New”,10),新SolidBrush(颜色。红色),20,5);
//Graphics类也有很多画图的方法,可以画直线,曲线,圆等等。
形象。Save(thefullname,System。drawing . imaging . image format . gif);
return“/now time . gif”;
}
}
}
///////////////////////////////////////////
& lt% @ page language = " c# " & gt;
& lt% @ Import namespace = " Wmj " % & gt
& ltscript language = " c# " runat = " server " & gt;
void Page_Load(对象发送方,事件参数e)
{
MyTempImage MyTempImage = new MyTempImage();
img1。Src=myTempImage。create image();
}
& lt/script & gt;
& lthtml & gt
& lthead & gt
& lt!-每10秒自动刷新一次-->
& ltmeta http-equiv = " refresh " content = " 10 " >
& lt/head & gt;
& ltbody & gt
& ltform runat = " server " & gt
& ltInput type="button" value= "手动刷新" onclick="location.reload()" >
& ltimg id = " img 1 " runat = " server "/& gt;
& lt/form & gt;
& lt/body & gt;
& lt/html & gt;