Sunday, June 22, 2008

Dynamically Add Watermark On Image in ASP.Net - sample code for add runtime watermark

Dynamically Add Watermark On Image ASP.NET C#
How to create watermark on image. you can simply create watermarks text on image
//used namespaces

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

///Locate Image from Image folder.
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("images/Copy.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 Brushe
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(113, 255, 255, 255));
g.DrawString("Raju.M C# Programmer Kerala,India.Dynamic WaterMark sample", new Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100);
Response.ContentType = "image/jpeg";//setting ContentType
bitmapimage.Save(Response.OutputStream, ImageFormat.Jpeg);//save image with dynamic watermark
Download Source


Rachit Gaur said...

It is really good. Thanks for this

vikranthreddy said...

it is good.
but my requrement is save this water marked image to databas.
iam using sqlserver please send me code.

vikranthreddy said...

dynamic watermarking working fine.
but my requriment is save this water mark image into sqlserver database.
please send me code.

Raju.M said...

@vikranthreddy Save bitmap binary data in your database

Pushkar said...

Hello Mr Raju.
Thanks for nice post.

i want to make this kind of watermark.

Is it possible ? Yes then how ?