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

ASP
认识和优化connection对象
优化你的ASP程序
ASP实现简单的网页保护
在ASP中限制同一表单被多次提交
Request 对象 属性和方法
asp的Request对象
全角与半角字符的相互转换的asp函数
asp session 使用数组
防止ASP Session丢失的方法
cookies和session的关系
无组件不能上传rar,zip其它非图片文件
网站设计时应注意的SEO细节
asp代码--fso创建文件夹
ASP转化ip地址为长整型数字
关于script的dictionary对象的用法
asp过滤不文明字符的函数
fso删除当前文件夹下所有的内容
asp中将字符转换成变量使用
asp数组随机排序
解决asp被杀毒软件误删的方法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 155 ::
收藏到网摘: 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 >

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