usingSystem;usingSystem.Collections;usingSystem.Data;usingSystem.Linq;usingsystem.web;usingSystem.Web.Services;usingSystem.Web.Services.Protocols;usingSystem.Xml.Linq;usingSystem.IO;usingSystem.Drawing;namespacewebapptest{/// <summary> ///Summary description of $codebehindclassname $/// </summary>[WebService (Namespace ="http://tempuri.org/")] [WebServiceBinding (ConformsTo=Wsiprofiles.basicprofile1_1)] Public classUpload:ihttphandler { Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; Httppostedfile HPF= Context. request.files["Upload"]; if(HPF. ContentLength >0) { stringPath = context. Server.MapPath ("~/resource/image/"); if(!directory.exists (path)) {directory.createdirectory (path); } stringfilename =HPF. FileName; stringNewFileName = DateTime.Now.ToFileTime () +path.getextension (filename); stringFullName = path +NewFileName; Hpf. SaveAs (fullname); stringWatermarkfilename = context. Server.MapPath ("~/resource/image/logo.png"); Addwatermark (fullname, watermarkfilename); Context. Response.Write ("Upload Success"); } Else{context. Response.Write ("Select File"); } } Public BOOLisreusable {Get { return false; } } /// <summary> ///Add Watermark/// </summary> /// <param name= "FullName" >the full path of the watermark picture needs to be added</param> /// <param name= "Watermarkfilename" >full path of watermark picture</param> Public voidAddwatermark (stringFullNamestringwatermarkfilename) { //D:\projects\VS2008\WebAppTest\WebAppTest\resource\image end no ' \ ' stringDicname =Path.getdirectoryname (fullname); stringNewFileName = DateTime.Now.ToFileTime () +path.getextension (fullname); stringNewfullname = Dicname +"/"+NewFileName; Bitmap BMP=NewBitmap (fullname); intwidth =bmp. Width; intHeight =bmp. Height; Bitmap logo=NewBitmap (watermarkfilename); //Set Transparentlogo. Maketransparent (); using(Graphics g =graphics.fromimage (BMP)) { //Add a border to a pictureG.drawrectangle (NewPen (Color.green,6),NewRectangle (0,0, Width,height)); //Add WatermarkG.drawimage (logo,width-6-logo. width,height-6-logo. Height); } BMP. Save (Newfullname); Bmp. Dispose (); Logo. Dispose (); } }}
C # add watermark to pictures