Thursday 6 June 2013

Set Watermark text on image in c#

using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Drawing.Imaging;


protected void Page_Load(object sender, System.EventArgs e)
{
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("Chrysanthemum.jpg"));


//Taken Actual width anf height From Image
int height = objImage.Height;
//height
int width = objImage.Width;
//Width
//Create a Bitmap Image
System.Drawing.Bitmap bitmapimage = new System.Drawing.Bitmap(objImage, width, height);
// create bitmap with same size of Actual image
//Convert in to a Graphics object
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapimage);
//Creating Brush
//set text position on image
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(113, 255, 255, 255));


g.DrawString(" Anish ", new Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100);
Response.ContentType = "image/jpeg";
//setting ContentType


bitmapimage.Save(Response.OutputStream, ImageFormat.Jpeg);
}


It will display watermark text on image

No comments:

Post a Comment