using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.IO;
using System.Drawing; namespace WebAppTest
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class upload : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{ context.Response.ContentType = "text/plain"; HttpPostedFile hpf = context.Request.Files["upload"]; if (hpf.ContentLength > )
{
string path = context.Server.MapPath("~/resource/image/"); if (!Directory.Exists(path))
{ Directory.CreateDirectory(path);
} string filename = hpf.FileName; string newFilename = DateTime.Now.ToFileTime() + Path.GetExtension(filename); string fullname = path + newFilename; hpf.SaveAs(fullname); string waterMarkFileName = context.Server.MapPath("~/resource/image/logo.png"); AddWaterMark(fullname, waterMarkFileName); context.Response.Write("upload success"); }
else
{
context.Response.Write("select file");
} } public bool IsReusable
{
get
{
return false;
}
}
/// <summary>
/// 加上水印
/// </summary>
/// <param name="fullname">需要加上水印图片的全路径</param>
/// <param name="waterMarkFileName">水印图片的全路径</param>
public void AddWaterMark(string fullname,string waterMarkFileName)
{ //D:\projects\VS2008\WebAppTest\WebAppTest\resource\image 结尾没有'\'
string dicName = Path.GetDirectoryName(fullname); string newFilename = DateTime.Now.ToFileTime() + Path.GetExtension(fullname); string newFullname = dicName + "/" + newFilename; Bitmap bmp = new Bitmap(fullname); int width = bmp.Width; int height = bmp.Height; Bitmap logo = new Bitmap(waterMarkFileName); //设置透明
logo.MakeTransparent(); using(Graphics g = Graphics.FromImage(bmp))
{
//将图片加上边框
g.DrawRectangle(new Pen(Color.Green,),new Rectangle(,,width,height)); //加上水印
g.DrawImage(logo,width--logo.Width,height--logo.Height); } bmp.Save(newFullname); bmp.Dispose();
logo.Dispose(); }
}
}

最新文章

  1. ConcurrentAsyncQueue 2014-09-07
  2. Android下集成Paypal支付
  3. 09-FZ6R 白色
  4. iOS多线程编程之NSThread的使用(转)
  5. about云资源共享
  6. jquery动态创建form并提交到.ashx文件处理
  7. HDOJ 2191
  8. 使用NUnit进行项目的单元测试
  9. HttpClient---------demo
  10. Jquery Mobile 记录
  11. 《JavaScript高级程序设计》读书笔记 ---基本包装类型
  12. [转载] Redis-benchmark使用总结
  13. win10下 github+hexo搭建个人博客.md
  14. scala的多种集合的使用(7)之集Set的操作方法
  15. 自适应rem.js
  16. mysql5.6 主从同步配置
  17. mvn打包到私服的命令
  18. TDSQL“相似查询工具MSQL+”入选VLDB论文
  19. January 01st, 2018 Week 01st Monday
  20. Windows 10官方原版ISO制作方法

热门文章

  1. C#.字符串转数组,数组转字符串
  2. pgm12
  3. FieldGroup绑定ItemDataSource
  4. linux上搭建nginx
  5. Change upload file limit in specified Webapllication in SharePoint (PowerShell)
  6. 【codeforces 103E】 Buying Sets
  7. android关闭日志
  8. AtCoder Grand Contest 010 D - Decrementing
  9. 1: Myeclipse10 优化设置
  10. hdu 4685(强连通分量+二分图的完美匹配)