Using System; Using System. Collections; Using System. ComponentModel; Using System. Data; Using System. Drawing; Using System. Web; Using System. Web. SessionState; Using System. Web. UI; Using System. Web. UI. WebControls; Using System. Web. UI. HtmlControls; Using System. IO;Namespace uploadfiles { Public class 35 cnnet: System. Web. UI. Page { Protected System. Web. UI. WebControls. Button Button1; Protected System. Web. UI. HtmlControls. HtmlInputFile File1; Protected System. Web. UI. WebControls. Image Image1; Protected System. Web. UI. WebControls. RequiredFieldValidator RequiredFieldValidator1; Protected System. Web. UI. WebControls. Label Label1; Protected System. Web. UI. WebControls. Button Button2; Private void Page_Load (object sender, System. EventArgs e) { // Place user code here to initialize the page If (! Page. IsPostBack) { Image1.ImageUrl = "aa.gif "; } } # Code generated by region Web Form Designer Override protected void OnInit (EventArgs e) { // // CODEGEN: This call is required by the ASP. NET Web form designer. // InitializeComponent (); Base. OnInit (e ); } /// <Summary> /// The designer supports the required methods-do not use the code editor to modify /// Content of this method. /// </Summary> Private void InitializeComponent () { This. Button1.Click + = new System. EventHandler (this. button#click ); This. Button2.Click + = new System. EventHandler (this. Button2_Click ); This. Load + = new System. EventHandler (this. Page_Load ); } # Endregion Private void button#click (object sender, System. EventArgs e) { If (File1.PostedFile. FileName. Trim ()! = "") { // Upload a file String extension = Path. GetExtension (File1.PostedFile. FileName). ToLower (); String fileName = DateTime. Now. ToString ("yyyyMMddhhmmss "); String path = Server. MapPath (".") + "/upload/" + fileName + extension; File1.PostedFile. SaveAs (path ); // Add a text watermark. Note that the code here cannot coexist with the image watermark code below. System. Drawing. Image image = System. Drawing. Image. FromFile (path ); Graphics g = Graphics. FromImage (image ); G. DrawImage (image, 0, 0, image. Width, image. Height ); Font f = new Font ("Verdana", 16 ); Brush B = new SolidBrush (Color. Blue ); String addText = "Hundred Percent design "; G. DrawString (addText, f, B, 10, 10 ); G. Dispose (); // Save the watermark image and delete the original image String newPath = Server. MapPath (".") + "/upload/" + fileName + "_ new" + extension; Image. Save (newPath ); Image. Dispose (); If (File. Exists (path )) { File. Delete (path ); } Image1.ImageUrl = newPath; // Response. Redirect (newPath ); } } Private void Button2_Click (object sender, System. EventArgs e) { // Upload a file String extension = Path. GetExtension (File1.PostedFile. FileName). ToUpper (); String fileName = DateTime. Now. ToString ("yyyyMMddhhmmss "); String path = Server. MapPath (".") + "/upload/" + fileName + extension; File1.PostedFile. SaveAs (path ); // Add an image watermark System. Drawing. Image image = System. Drawing. Image. FromFile (path ); System. Drawing. Image copyImage = System. Drawing. Image. FromFile (Server. MapPath (".") + "/lz.jpg "); Graphics g = Graphics. FromImage (image ); G. DrawImage (copyImage, new Rectangle (image. Width-copyImage.Width, image. Height-copyImage.Height, CopyImage. Width, copyImage. Height), 0, 0, copyImage. Width, copyImage. Height, GraphicsUnit. Pixel ); G. Dispose (); // Save the watermark image and delete the original image String newPath = Server. MapPath (".") + "/upload/" + fileName + "_ new" + extension; Image. Save (newPath ); Image. Dispose (); If (File. Exists (path )) { File. Delete (path ); } Image1.ImageUrl = newPath; } } } |