Click here to Skip to main content
Click here to Skip to main content

How to Create watermarked images in C# ASP.NET ?

By , 3 Feb 2012
 
The below code will create a watermark on image using C#.
 
//Use NameSpace
using System.Drawing;
 
//Execute below code at the event, where u wants Water Marking. 
{ 
           // Create a bitmap object of the Image, Here I am taking image from File Control "FileTest" 
            Bitmap bmp = new Bitmap(FileTest.PostedFile.InputStream); 
            Graphics canvas = Graphics.FromImage(bmp); 
            try 
            { 
                Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height); 
                canvas = Graphics.FromImage(bmpNew); 
                canvas.DrawImage(bmp, new Rectangle(0, 0, 
bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, 
GraphicsUnit.Pixel); 
                bmp = bmpNew; 
            } 
            catch(Exception ee) // Catch exceptions 
            { 
                Response.Write(ee.Message); 
            } 
            // Here replace "Text" with your text and you also can assign Font Family, Color, Position Of Text etc. 
            canvas.DrawString("Text", new Font("Verdana", 14, 
FontStyle.Bold), new SolidBrush(Color.Beige), (bmp.Width / 2), 
(bmp.Height / 2)); 
            // Save or display the image where you want. 
            bmp.Save(System.Web.HttpContext.Current.Server.MapPath("~/ 
WaterMarkImages/") + 
FileTest.PostedFile.FileName, 
System.Drawing.Imaging.ImageFormat.Jpeg); 
} 
 
You will find a great solution. :-D

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sarvesh Kumar Gupta
Team Leader Edge Business Solution Pvt. Ltd.
India India
Member
Working as Team Leader in a product development company with 6.5 years of exp. in .net.
 
I have worked on Windows and Web based projects.
 
My skills - C#, ASP.Net, SQL, Javascript, HTML, Ajax, LINQ etc.
 
My interesting domain: ERP Domain, Finance, Inventory, Manufacturing, Billing etc.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionwatermark on imagesmemberTarcode Michael5 Jan '13 - 17:13 
This is really great, I generates some bar codes and want to put some watermark. Not sure if it will affect scanning, but will have a try.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 3 Feb 2012
Article Copyright 2012 by Sarvesh Kumar Gupta
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid