一般处理程序ashx结合gdi+处理图片
2014-05-23 15:07
218 查看
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);
}
}
}
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);
}
}
}
相关文章推荐
- 如何读取二进制图片-.ashx一般处理程序 --1
- 如何读取二进制图片-.ashx一般处理程序
- 如何读取二进制图片-.ashx一般处理程序
- 在ashx一般处理程序文件中不能使用session和request的问题解决办法
- 最近学习asp.net一般处理程序(.ashx)
- 用一般处理程序做的图片验证码
- .NET中一般处理程序(ashx)在Ajax中的使用--下拉列表的动态级连
- 一般处理程序.ashx获取不到session
- 一般处理程序.ashx
- Handler一般处理程序的应用--随机图片生成
- 一般处理程序.ashx的应用
- ASP.NET ASHX 一般处理程序教程
- Asp.net jQuery与ashx 安全性问题 (一般处理程序的安全问题) ashx 安全
- asp.net .ashx一般处理程序中使用session
- Asp.net jQuery与ashx 安全性问题 (一般处理程序的安全问题) ashx 安全
- ASP.net的HTTP处理程序(ASHX)提取dll内嵌资源图片
- 在ashx一般处理程序文件中不能使用session和request的问题解决办法
- 一般处理程序(.ashx)中处理cookies的方法解决
- .NET中一般处理程序(ashx)在Ajax中的使用--下拉列表的动态级连
- .NET中一般处理程序(ashx)在Ajax中的使用