Knowledge point:
1. First create an image, then create a watermark image, and then create a canvas graphic
Problem:
Place a watermark on the Image
Solution
1 <% @ webhandler Language = "C #" class = "shuiyin" %> 2 3 using system; 4 using system. web; 5 using system. drawing; 6 7 public class shuiyin: ihttphandler {8 9 Public void processrequest (httpcontext context) {10 context. response. contenttype = "text/JPEG"; 11 // context. response. write ("Hello World"); 12 // read the source image 13 using (image IMG = system. drawing. image. fromfile (context. server. mappath ("download/1.jpg") 14 {15 // read the watermark image 16 using (image imgwater = image. fromfile (context. server. mappath ("download/2.jpg") 17 {18 // create a" canvas "19 using (Graphics G = graphics. fromimage (IMG) 20 {21 // draw the watermark image to the "source image" for 22 GB. drawimage (imgwater, new rectangle (100,100, imgwater. width, IMG. height), new rectangle (0, 0, imgwater. width, imgwater. height), graphicsunit. pixel); 23} 24 IMG. save (context. response. outputstream, system. drawing. imaging. imageformat. JPEG); 25} 26} 27} 28 29 public bool isreusable {30 get {31 return false; 32} 33} 34 35}
View code
Image operations: Add a watermark to the image