Now many websites of news images have a watermark logo of their own website, I want to do it. The principle to add watermarks is actually very simple. Build a coating. This coating draws on the mark you want to add. After setting the color and transparency, it is possible with this coating and the original picture. Below is the code of this function: This is a common function that can be sent in any where you need. Give a function to pass an original image of Image object. The function returns an image object that adds watermark. Then I will listen to you. System.Drawing.Image CopyRight (System.Drawing.Image originalimage) {int height = originalimage.Height; // long int width obtained image = originalimage.Width; // get image width int FontSize = 50; // set the font Size int point_x = 1; // Watermark horizontal horizontal horizontal horizontal intangia = 1; // Water-silver left upper corner Graphics o_layer = graphics.fromimage (OriginalImage); sizef sizeofstring = new sizef (width, height); // This object is used to measure the long width while to add watermark // set the appropriate font size {sizeofstring = o_layer.measureString ("Copyright Rock", New Font ("Song", FontSize, FontStyle.Bold) ; if (SizeOfString.Width Break;) // Sets the starting point IF (width> sizeofstring.width) Point_x = width- (int) SizeOfString.Width-10; if (Height> SizeOfstring.Height) Point_y = height- (int) sizeofstring.height-10; // painting watermark, the color of the brush can modify O_Layer.drawstring according to your own preferences, New Font ("Song, Fontsize, FontStyle. Bold), New Solidbrush (Color.Fromargb (40, 180, 180, 180), New Pointf (Point_x, Point_Y)); O_Layer.Save (); // Save Watermark to Image Return OriginalImage } The following is the use of this function, give the image to the image when the image is added to the picture: only the program of the background page is given here. Just add a panel and button in the ASPX page. The IDs are Panel1 and Button1, respectively. immediately. This example enables multi-file simultaneous upload by modifying the value of n in the biuld_file function. using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Web; using System.Web.SessionState; using System.Web.UI; using System. Web.ui.WebControls; use system.web.ui.htmlcontrols; Namespace graphicscopyright {///// WebForm1 summary description.
/// public class WebForm1: System.Web.UI.Page {protected System.Web.UI.WebControls.Panel Panel1; protected System.Web.UI.WebControls.Button Button1; private void Page_Load (object sender, System.EventArgs e ) {// Place user code here to initialize page BIULD_FILE (Sender, e);} public void biull_file (Object sender, system.eventargs e) {int N = 1; if (n> 0) {for (int I = 0; i {htmlinputfile hif = new htmlinputfile (); // Initialization Control Panel1.controls.add (hifi);}}} #Region Web Form Designer Generated Code Override Protected Void OnInit (Eventargs E) {/ / // codegen: This call is necessary for the ASP.NET Web Form Designer. // InitializationComponent () Base.onit (E);} // /// Designer Support required - Do not use the code editor to modify the // this method.
/// private void InitializeComponent () {this.Button1.Click = new System.EventHandler (this.Button1_Click); this.Load = new System.EventHandler (this.Page_Load);} #endregion private void Button1_Click (object sender System.Eventargs e) {string fileinfor = ""; string path = request.physicalApplicationPath; int numfile = request.files.count; for (int i = 0; i {if (Request.Files.get (i) .contentLENGTH > 0) {fileinfor = request.files.get (i) .FileName; string filetype = request.files.get (i) .contettype; string filename = system.io.path.getFileName (fileinfor); fileinfor = system.io .Path.combine (system.io.path.combine (path, "upload"), filename; stream fs = request.files.get (i) .inputstream; System.Drawing.Image img = System.Drawing.Image.FromStream (fs, false); System.Drawing.Image _img = CopyRight (img); try {_img.Save (fileinfor); Response.Write (filename "Success! ");} Catch {response.write (" Upload Failed! ");}}}} System.drawing.image copyright (system.drawing.image originalimage) {system.drawing.image o =