当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在网页中动态的生成一个gif图片

ASP
ASP技巧:让Len,Left,Right函数识别中文
Flash和ASP实现的用户登录/注册程序
ASP随机显示不重复记录解决方案
ASP动态网页制作常用错误处理
ASP对网页进行限制性的访问
初学:ASP内建对象Response
ASP Server object error的解决办法
ASP教程,ASP实现防盗链的方法
更改windows XP 的IIS连接数
xmldom在服务器端生成静态html页面
asp技巧:防止被杀毒软件误删的代码
ASP教程:初步接触ASP缓存技术
ASP教程:rs.getrows的使用方法介绍
ASP技巧:Utf-8和Gb2312乱码问题的终结
ASP教程:applicaton对象的使用集合
ASP环境:启动停止IIS不重启电脑的技巧
利用FLV组件制作的播放器,动态获取变量,控制FLV文件
ASP教程:ASP错误ASP 0201的解决方法
ASP技巧教程:认识学习codepage的属性
Codepage参数和其对应的语言

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 97 ::
收藏到网摘: n/a

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

namespace Wmj
{
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";
}
}
}
///////////////////////////////////////////
< %@page language="C#"% >
< %@Import namespace="Wmj"% >
< script language="C#" runat="server" >
void Page_Load(object sender,EventArgs e)
{
MyTempImage myTempImage=new MyTempImage();
img1.Src=myTempImage.CreateImage();
}
< /script >
< html >
< head >
< !--每10秒自动刷新-- >
< meta http-equiv="refresh" content="10" >
< /head >
< body >
< form runat="server" >
< input type="button" value="手动刷新" onclick="location.reload()" >
< img id="img1" runat="server"/ >
< /form >
< /body >
< /html >

有了这个例子的原理动态的显示数据库中数据的曲线图、比例饼图、柱状图等都应该不成问题了。