C#动态添加带文字图片
首先:在一般处理程序中写
context.Response.ContentType = "image/JPEG";
string name=context.Request["Name"];//有前台传递过来的参数
string fullPath = HttpContext.Current.Server.MapPath("动态图片.jpg");
using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(fullPath))
{
using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(bitmap))
{
g.DrawString(name, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 220, 40);//220, 40是文字显示在图片中的位置
}
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}
//最终这个一般处理程序就在页面上产生了一张带文字的图片
其次:在前端可以用img标签显示,代码如下:
document.getElementById("imgId").src = "一般处理程序页面?Name=参数值" ;