In the following code, adding a text watermark and an image watermark cannot coexist (the following is written together 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-