Http://www.cnblogs.com/index/archive/2004/10/20/54498.aspx
In the following code, the code for adding a text watermark and an image watermark cannot coexist.
I wrote a piece for ease of display.
Private void btn_upload_click (Object sender, system. eventargs E)
{
If (uploadfile. postedfile. filename. Trim ()! = "")
{
// Upload a file
String extension = path. getextension (uploadfile. postedfile. filename). toupper ();
String filename = datetime. now. year. tostring () + datetime. now. month. tostring () + datetime. now. day. tostring () + datetime. now. hour. tostring () + datetime. now. minute. tostring () + datetime. now. second. tostring ();
String Path = server. mappath (".") + "/uploadfile/" + filename + extension;
Uploadfile. 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", 32 );
Brush B = new solidbrush (color. White );
String addtext = addtext. value. Trim ();
G. drawstring (addtext, F, B, 10, 10 );
G. Dispose ();
// Add an image watermark
System. Drawing. Image image = system. Drawing. image. fromfile (PATH );
System. Drawing. Image copyimage = system. Drawing. image. fromfile (server. mappath (".") + "/alex.gif ");
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 (".") + "/uploadfile/" + filename + "_ new" + extension;
Image. Save (newpath );
Image. Dispose ();
If (file. exists (PATH ))
{
File. Delete (PATH );
}
Response. Redirect (newpath );
}