Friday, September 25, 2009

Add CopyRight Label to the Images - ASP.NET

Add CopyRight label to the images in the site sometimes is mandatory, you can change all images and add copyright label on some programs such as microsoft paint /adobe photoshop and ... and you should always do the same thing in this way, there is another way in .NET which help you not to do this fraustraiting job and use the following class in your project ,add specific Copyright label to the image, and everytime the user requests an image call the following function whithin a class. This sample is my favorite one :-)
Sample Image :

Adding copyright label to the image

public class ChangeImage
public System.Drawing.Image AddCopyRightToImage(System.Drawing.Image img)

// Define the Bitmap, Graphics, Font, and Brush for copyright logo
Graphics g = Graphics.FromImage(img);
Font f = new Font("Arial", 9);

// Create the foreground text brush
Brush b = new SolidBrush(Color.White);

// Create the backround text brush
Brush bb = new SolidBrush(Color.White);

// Add the copyright text background
string ct = "Copyright 2009, Company Name , Inc.";

//Set Label Alighnment
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;

// Add the copyright text foreground
g.DrawString(ct, f, b, img.Width / 2, 20, sf);

g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);

return img;


1 comment:

Thank you for sharing your knowledge and experiences with this weblog.