C # image watermark code sorting

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.