------- Windows Phone 7 Mobile Phone development,. Net training, and we look forward to communicating with you! -------
Attach a specified watermark to all the images in the specified directory as learned in the course;
You need to create a class and inherit: ihttphandler
The Code is as follows:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. drawing; using system. drawing. imaging; using system. io; // <summary> /// Summary of coverhandler // </Summary> public class coverhandler: ihttphandler {// all the URLs of the image to be added with the watermark public const string oldimageurl = "~ /Admin/bookconvers/"; // watermark image public const string waterurl = "~ /Admin/images/watermark.jpg "; // default image public const string defaultimage = "~ /Admin/images/default.jpg "; Public coverhandler () {// todo: add the constructor logic here //} public void processrequest (httpcontext context) {// string Path = context. request. mappath (oldimageurl + context. request. params ["ISBN"] + ". jpg "); system. drawing. image cover; // determines whether the file if (file. exists (context. request. physicalpath) {// load the file // cover = image. fromfile (context. request. physicalpath); cover = image. fromfile (context. request. physicalpath); // load the watermark image watermark = image. fromfile (context. request. mappath (waterurl); // instantiate the canvas graphics G = graphics. fromimage (cover); // draw the watermark G on the cover. drawimage (watermark, new point (cover. width-watermark. width, cover. height-watermark. height); // release the canvas G. dispose (); // release the watermark image watermark. dispose (); // Save the output stream cover. save (context. response. outputstream, system. drawing. imaging. imageformat. JPEG); // end the output cover. dispose (); context. response. end ();} else {cover = image. fromfile (context. request. mappath (defaultimage) ;}} public bool isreusable {get {return false ;}}}
Configuration file:
Because the image size affects the watermark position in the image, try to use images of the same size.
Watermark:
------- Windows Phone 7 Mobile Phone development,. Net training, and we look forward to communicating with you! -------