/// <summary>
/// _02UpLoad 的摘要说明
/// </summary>
public class _02UpLoad : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//HttpPostedFile file=context.Request.Files[0];
//if (file.ContentLength > 0)
//{
// string strName = System.IO.Path.GetFileName(file.FileName);
// file.SaveAs(context.Server.MapPath("/UpLoad/"+strName));
//}
//======================================加文字水印=====================================================
StringBuilder sbMsg = new StringBuilder();
for (int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile file = context.Request.Files[i];
if (file.ContentType.Contains("image/"))
{
if (file.ContentLength>0)
{
using (Image img=Image.FromStream(file.InputStream))
{
using ( Graphics g=Graphics.FromImage(img))
{
g.DrawString("传奇",new Font("微软雅黑",16),Brushes.Red,0,0);
}
string strName = System.IO.Path.GetFileName(file.FileName);
string PhyPath = context.Server.MapPath("/UpLoad/" + strName);
img.Save(PhyPath);
sbMsg.AppendLine(strName+"<br/>");
}
}
}
}
context.Response.Write("上传成功!<br/>" + sbMsg.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
============================================加图片水印======================================================
StringBuilder sbMsg = new StringBuilder();
for (int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile file = context.Request.Files[i];
if (file.ContentType.Contains("image/"))
{
if (file.ContentLength>0)
{
using (Image img=Image.FromStream(file.InputStream))
{
using (Image imgWater = Image.FromFile(context.Server.MapPath("/UpLoad/adidas.jpg")))
{
using (Graphics g = Graphics.FromImage(img))
{
g.DrawImage(imgWater,0,0);
}
}
string strName = System.IO.Path.GetFileName(file.FileName);
string PhyPath = context.Server.MapPath("/UpLoad/" + strName);
img.Save(PhyPath);
sbMsg.AppendLine(strName+"<br/>");
}
}
}
}
context.Response.Write("上传成功!<br/>" + sbMsg.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}