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

  大家知道股票网站的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 />
</form>
</body>
</html>

相关文章:

  • 2021-08-07
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-12-20
  • 2021-12-18
猜你喜欢
  • 2021-11-07
  • 2022-03-02
  • 2021-09-01
  • 2021-11-06
  • 2022-02-15
相关资源
相似解决方案