2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > ashx返回图片_一般处理程序ashx结合gdi+处理图片

ashx返回图片_一般处理程序ashx结合gdi+处理图片

时间:2021-05-26 15:17:25

相关推荐

ashx返回图片_一般处理程序ashx结合gdi+处理图片

1 新建一般处理程序 .ashx

public void ProcessRequest (HttpContext context) {

context.Response.ContentType = "text/plain";

context.Response.Write("Hello World");

}

2. 引入命名空间 using System.Drawing;

3.因为是操作图片所以把context.Response.ContentType = "text/plain";改为context.Response.ContentType = "image/jpeg";

4

//一般处理程序中给图片添加文字

string path = context.Request.MapPath("psb.jpg");

using (Image img = Image.FromFile(path))

{

using (Graphics g = Graphics.FromImage(img))

{

g.DrawString("文字", new Font("黑体", 40), Brushes.Red, 120, 120);

img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

}

}

5

//给图片添加logo

string imagepath = context.Request.MapPath("psb.jpg");

string loginpath = context.Request.MapPath("logo.png");

using (Image img=Image.FromFile(imagepath))

{

using (Image logoimage=Image.FromFile(loginpath))

{

using (Graphics g=Graphics.FromImage(img))

{

g.DrawImage(logoimage, 100, 200, logoimage.Width, logoimage.Height);

img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。