I have modified the code from that article. But please note you will have to make adjustments in X and Y values based on the Image Height and Width.
Namespaces
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
Code
protected void Upload(object sender, EventArgs e)
{
string watermarkText = "© ASPSnippets.com";
//Get the file name.
string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName) + ".png";
//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(FileUpload1.PostedFile.InputStream, false))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.FromArgb(99, Color.Black));
//Set the Font and its size.
Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);
//Determine the size of the Watermark text.
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
//Position the text and draw it on the image.
Point position = new Point((bmp.Width / 2), (bmp.Height / 2));
//Rotate and Draw
grp.TranslateTransform(position.X / 2, position.Y / 2);
grp.RotateTransform(-45);
grp.DrawString(watermarkText, font, brush, position.X - ((int)textSize.Width + 10), position.Y - ((int)textSize.Height + 10));
grp.ResetTransform();
using (MemoryStream memoryStream = new MemoryStream())
{
//Save the Watermarked image to the MemoryStream.
bmp.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
//Start file download.
Response.Clear();
Response.ContentType = "image/jpg";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
//Write the MemoryStream to the Response.
memoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.Close();
Response.End();
}
}
}
}
Screenshot
