Asp tutorial. net image watermark classic code
To prevent the image from being reprinted and used by others, we will process the image watermark.
<% @ WebHandler Language = "C #" Class = "BookHandler" %>
Using System;
Using System. Web;
Using System. Drawing;
Using System. IO;
Public class BookHandler: IHttpHandler {
Private const string COVERSADDR = "~ /Image/"; // cover folder path
Private const string WATERMARK_URL = "~ /Images/WaterMark.jpg "; // digital watermark path
Private const string DEFAULT_URL = "~ /Images/default.jpg "; // default image path
Public void ProcessRequest (HttpContext context ){
String path = context. Request. MapPath (COVERSADDR + context. Request. Params ["ISBN"]. ToString () + ". jpg ");
Image Cover;
If (File. Exists (path ))
{
Cover = Image. FromFile (path );
Image watermark = Image. FromFile (context. Request. MapPath (WATERMARK_URL ));
Graphics g = Graphics. FromImage (Cover );
G. drawImage (watermark, new Rectangle (Cover. width-watermark. width, Cover. height-watermark. height, watermark. width, watermark. height), 0, 0, watermark. width, watermark. height, GraphicsUnit. pixel );
G. Dispose ();
Watermark. Dispose ();
}
Else
{
Cover = Image. FromFile (context. Request. MapPath (DEFAULT_URL ));
}
Context. Request. ContentType = "image/ipeg ";
Cover. Save (context. Response. OutputStream, System. Drawing. Imaging. ImageFormat. Jpeg );
Cover. Dispose ();
Context. Response. End ();
}
Public bool IsReusable {
Get {
Return false;
}
}
}
Finally, change the path of the connected image
BookCover. ashx? ISBN = number.