<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="js/jquery-1.5.2.js"></script>
<script type="text/javascript">
$(function () {
$("#yanzenma").click(function () {
var img = document.getElementById("yanzenma");
img.src = "yanzenma.ashx?" + new Date();
});
});
</script>
</head>
<body>
<img src="yanzenma.ashx" id="yanzenma" />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="js/jquery-1.5.2.js"></script>
<script type="text/javascript">
var GenXin = function () {
var img = document.getElementById("yanzenma");
img.src = "yanzenma.ashx?" + new Date();
};
</script>
</head>
<body>
<img src="yanzenma.ashx" id="yanzenma" onclick="GenXin()"/>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace lianxi03
{
/// <summary>
/// yanzenma 的摘要说明
/// </summary>
public class yanzenma : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
Random r = new Random();
int a = r.Next(1000,10000);
context.Session["yanzenma"] = a;
using (Bitmap bmp = new Bitmap(50, 25))
{
using (Graphics g = Graphics.FromImage(bmp))
using (Font font = new Font(FontFamily.GenericSerif, 15))
{
g.DrawString(a.ToString(), font, Brushes.Red, new PointF(0, 0));
}
bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
原文地址:https://www.cnblogs.com/lijian0755/p/8856031.html