This section of the company has a project. The customer requires that the uploaded image be subject to a custom watermark. I used to discuss the problem of C # image watermark with my friends, but I have never actually tried it. So I took this opportunity to study the C # image watermark function! I am referring to the Code in the discuz forum. In this way, the image to be uploaded is directly converted to System. drawing. you do not need to save the Image to the server disk, add the watermark to redraw the Image, and save it to the server disk. Then you can take it out for drying:
1 /// <summary>
2 // Add an image watermark
3 /// </summary>
4 /// <param name = "img"> source image watermark (System. Drawing) </param>
5 // <param name = "filename"> file name </param>
6 /// <param name = "watermarkFilename"> watermark file name </param>
7 // <param name = "watermarkStatus"> image watermark position 1 = top left 2 = Top 3 = Top right 4 = middle left 5 = middle 6 = middle right 7 = bottom left 8 = middle right 9 = bottom right </param>
8 // <param name = "quality"> the watermark quality ranges from 0 ~ 100. The higher the number, the higher the Quality </param>
9 // <param name = "watermarkTransparency"> Transparency of the watermark image 1 ~ 10. The smaller the number, the more transparent it is. 10 is not transparent. </param>
10 public static void ImageWaterMarkPic (Image img, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
11 {
12 Graphics g = Graphics. FromImage (img );
13 // set a high quality Interpolation Method
14 // g. InterpolationMode = System. Drawing. Drawing2D. InterpolationMode. High;
15 // set high quality and smooth Low Speed
16 // g. SmoothingMode = System. Drawing. Drawing2D. SmoothingMode. HighQuality;
17 Image watermark = new Bitmap (watermarkFilename );
18
19 if (watermark. Height> = img. Height | watermark. Width> = img. Width)
20 return;
21
22 ImageAttributes imageAttributes = new ImageAttributes ();
23 ColorMap colorMap = new ColorMap ();
24
25 colorMap. OldColor = Color. FromArgb (255, 0,255, 0 );
26 co