The example of this article describes the ASP.net inheritance IHttpHandler interface implementation to the Web site image add watermark function. Share to everyone for your reference, specific as follows:
First show the picture effect:
1. Add the class file under App_Code, named Imagesy file as follows
public class Imagesy:ihttphandler {public Imagesy () {////todo: Add constructor logic//} #region Ihttphan
Dler member public bool IsReusable {get {true;} The public void ProcessRequest (HttpContext context) {//Gets the requested physical picture path string ImagePath = Context.
Request.PhysicalPath;
System.Drawing.Image Image = null;
if (file.exists (ImagePath)) {//define watermark text string text = "This picture comes to my Site";
Define watermark text font size int fontsize = 22;
Watermark text Fonts Font font = new Font ("XXFarEastFont-Arial", fontsize);
Load picture image by Physical address of picture = System.Drawing.Image.FromFile (ImagePath);
Graphics g = graphics.fromimage (image);
Gets the display area size required to draw the watermark text SizeF size = g.measurestring (text, font); if (size. Width > Image. Width | | Size. Height > Image.
Height) {} else {Brush Brush = brushes.red; g.DrawString (text, font, brush, image. Width-size. Width, image. Height-size.
Height);
G.dispose (); } else {} image. Save (context.
Response.outputstream, Imageformat.jpeg);
} #endregion}
2. Configure Webconfig, add location new node
<location path= "Images" >
<system.web>
3. Test, new ASPX page, display picture, Watermark will automatically add the
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.