Click here to Skip to main content
6,630,289 members and growing! (21,482 online)
Email Password   helpLost your password?
Multimedia » General Graphics » General     Beginner License: The Code Project Open License (CPOL)

Pixel Addition Watermarking

By vidyaputra

A application that shows how to add pixels to create a visible watermark without using GDI.
C#, .NET, Dev
Version:2 (See All)
Posted:17 Feb 2009
Views:6,418
Bookmarked:23 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 3.06 Rating: 3.38 out of 5

1
2 votes, 25.0%
2
2 votes, 25.0%
3
2 votes, 25.0%
4
2 votes, 25.0%
5

Introduction

In this article, I would like to explain about a visible watermarking method using pixel addition. I am writing this article because most articles I have read about visible watermarking use GDI (which, I think is complicated). So I thought, why not use simple math, considering that a pixel is a matrix value. In this application, I use Visual Studio 2005 with C#.

Background

A pixel in a digital image is a matrix value ranging between 0 - 255. So, in 1024 x 600 digital image, there will be 1024 x 600 pixels. How does the matrix addition work? Just add the cover image pixel value with the watermark pixel value.

result Pixel = cover Pixel + mark Pixel

To give an opacity option, use a double value as opacity ranging between 0.1 - 1.9, and then you will get:

result Pixel = cover Pixel + (mark Pixel * opacity)

Using the code

The code in C# for the pixel addition would be like this:

private int pixelVal(int avemark, int pixcover, double opacity)
{
    if (pixcover + (avemark * opacity) > 255)
    {
        return pixcover = 255;
    }
    else
    {
        return pixcover = Convert.ToInt32(pixcover + (avemark * opacity));
    }
}

And then on the Process button, simply process the whole matrix using a "for" loop. Just like in the code below:

watermarkBmp = (Bitmap)Bitmap.FromFile(openWatermark);
coverBmp = (Bitmap)Bitmap.FromFile(openCover);
resultBmp = null;
int red = 0;
int green = 0;
int blue = 0;
double opacity = Convert.ToDouble(comboBox1.Text);

for (int i = 0; i < watermarkBmp.Height; i++)
{
    for (int j = 0; j < watermarkBmp.Width; j++)
    {
        //kalau watermark terlalu besar, kenapa error?
        red = pixelVal(watermarkBmp.GetPixel(i, j).R, coverBmp.GetPixel(i, j).R, opacity);
        green = pixelVal(watermarkBmp.GetPixel(i, j).G, coverBmp.GetPixel(i, j).G, opacity);
        blue = pixelVal(watermarkBmp.GetPixel(i, j).B, coverBmp.GetPixel(i, j).B, opacity);
        coverBmp.SetPixel(i, j, Color.FromArgb(red, green, blue));
    }
}

pictureBox2.Width = coverBmp.Width;
pictureBox2.Height = coverBmp.Height;
pictureBox2.Image = coverBmp;

Points of interest

For me, using the matrix addition is much simpler than using GDI. And, it could have more options such as translation etc. Watermarking is fun, because there are many things to explore about it.

History

The first time I learned about watermarking was when I was working on my thesis about visible and invisible watermarking. But, when I searched for articles and code for visible watermarking, most of them were using GDI (brush, etc.). And, this is my first small version without using GDI.

License

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

About the Author

vidyaputra


Member

Occupation: Software Developer (Junior)
Location: Indonesia Indonesia

Other popular General Graphics articles:

  • A flexible charting library for .NET
    Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
  • CxImage
    CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
  • 3D Pie Chart
    A class library for drawing 3D pie charts.
  • Barcode Image Generation Library
    This library was designed to give an easy class for developers to use when they need to generate barcode images from a string of data.
  • ImageStone
    An article on a library for image manipulation.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
GeneralMy vote of 2 PinmemberQwertie5:16 28 Feb '09  
AnswerRe: My vote of 2 Pinmembervidyaputra21:44 5 Mar '09  
GeneralMy vote of 2 PinmemberQistoph0:14 18 Feb '09  
GeneralRe: My vote of 2 Pinmembervidyaputra19:02 18 Feb '09  
GeneralMessage Automatically Removed PinmemberMember 322005223:08 17 Feb '09  
GeneralRe: hi Pinmembervidyaputra19:00 18 Feb '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Feb 2009
Editor: Smitha Vijayan
Copyright 2009 by vidyaputra
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project