动态生成图片:

服务器:
//首先修改报文头
context.Response.ContentType = "image/png";
//获取用户发送过来的姓名和ip等信息
string strName = context.Request.QueryString["txtName"];//获取用户名
string ip = context.Request.UserHostAddress;//获取ip
//System.Drawing;
using (Image image = new Bitmap(300, 100))//封装GDI位图
{
//无论像图片添加啥内容,都需获取该图片的"画布"
Graphics g=Graphics.FromImage(image);
//设置图片背景色
g.Clear(Color.Pink);
//像图片中写一些字符串:姓名、IP
g.DrawString(strName + Environment.NewLine + ip, new Font("楷体", 20), Brushes.Black, 10,10);
//把创建好的图片发送给用户
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
}
客户端:
<form action="CreateImage.ashx" method="get">
请输入您的大名:<input type="text" name="txtName" value=""/><br />
<input type="submit" value="生成图片"/>
</form>

转载于:https://www.cnblogs.com/shuai7boy/p/5536850.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值