Friday, January 23, 2009

Watermarking an image in

CodeGlobeImagewatermarkingFirst we will select our background image.

Then we select our watermark image.

Now open a new project and add the reference System.Drawing.Imaging;

Next type the following code. Each line in the following code is sufficiently commented.

Image image = System.Drawing.Image.FromFile(@"C:\Ascent.jpg");//This is the background image
logo = Image.FromFile(@"C:\SUNFLOWR.JPG"); //This is your watermark
g = System.Drawing.Graphics.FromImage(image); //Create graphics object of the background image //So that you can draw your logo on it
Bitmap TransparentLogo = new Bitmap(logo.Width, logo.Height); //Create a blank bitmap object //to which we //draw our transparent logo
Graphics TGraphics = Graphics.FromImage(TransparentLogo);//Create a graphics object so that //we can draw //on the blank bitmap image object
ColorMatrix ColorMatrix = new ColorMatrix(); //An image is represenred as a 5X4 matrix(i.e 4 //columns and 5 //rows)
.Matrix33 = 0.25F;//the 3rd element of the 4th row represents the transparency
ImgAttributes = new ImageAttributes();//an ImageAttributes object is used to set all //the alpha //values.This is done by initializing a color matrix and setting the alpha scaling value in the matrix.The address of //the color matrix is passed to the SetColorMatrix method of the //ImageAttributes object, and the //ImageAttributes object is passed to the DrawImage method of the Graphics object.
ColorMatrixFlag.Default, ColorAdjustType.Bitmap); TGraphics.DrawImage(logo, new Rectangle(0, 0, TransparentLogo.Width, TransparentLogo.Height), 0, 0, TransparentLogo.Width, TransparentLogo.Height , GraphicsUnit.Pixel, ImgAttributes);
g.DrawImage(TransparentLogo, image.Width / 2, 30);
Save(@"C:\Test.jpeg", ImageFormat.Jpeg);

This is how the resulting image will look like.

kerala webdevelopers-webhosting providers


  1. sir pls help me to extract the original image
    from the watermarked image
    my id is

  2. you can't remove watermark from images.It's possible to edit image using any of the good image editing software.



Related Posts with Thumbnails