<% @ 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 "; // quantity
Watermark path
Private const string default_url = "~ /Images/default.jpg "; // default image
Film 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.
Configure jpg access in iis