Click here to Skip to main content
15,882,114 members
Articles / Desktop Programming / Windows Forms
Article

Watermark Creator

Rate me:
Please Sign up or sign in to vote.
4.48/5 (17 votes)
20 Jun 20052 min read 113.5K   5.2K   82   16
A tool which overlays a watermark and/or copyright statement on the bottom of an image.

Mark my Image Tool....

Introduction

I wanted to watermark a few sunset images taken by me, before posting it to internet. After searching for an hour or so, I couldn't find any freeware tool. All were shareware, means you have to buy, #$#$!@##!#@#@. I decided to make a tool on my own, many thanks to Joel Neubeck's article in CodeProject. Using his article, I just tried to create a proper user friendly GUI tool to mark images with copyright note, also optionally with your company logo.

You can call the tool Watermark Creator, Watermark tool or anything. I named it as MarkMyImage.

Sample watermarked image

The above image is taken from the internet, copyright to respected owner.

Using the code

You can download the source code, and modify it according to your needs, though I feel you need not modify anything :-).

  • Before running the application do not forget to run "MarkMyImage.reg". This will create the necessary keys into your registry (to store user preference).
  • Form_Load takes values from the system registry and initializes the screen.
  • You should now point your working folder to your image folder (input folder), where your images are located.
  • You can preview all the images, and select the required ones (by default, all images be selected).
  • By default, all output files will be generated as "[filename][suffix].ext", in the same folder. By default, the suffix is "_final".
  • You can set a different output folder, this way the output file name(s) will remain same.
  • Form_Closed saves all the current settings into the registry.

Class Watermark has two constructors, with or without the watermark image.

C#
WaterMark(string WorkingDirectory, string Copyright, Image ImgWatermark);
WaterMark(string WorkingDirectory, string Copyright);

According to user choice (watermark image preference), we will create the WaterMark object by passing the necessary parameters...

C#
if (chkWaterMarkImage.Checked == true)
    wm = new WaterMark(txtWorkingFolder.Text, 
                       txtCopyRight.Text,picWaterMark.Image);
else
    wm = new WaterMark(txtWorkingFolder.Text,txtCopyRight.Text);

Now, a simple execution loop for all the selected files.

C#
for(int i=0;i<lstFileList.CheckedItems.Count;i++)
{
    srcPic = txtWorkingFolder.Text + 
          lstFileList.Items[i].ToString().Substring(
          lstFileList.Items[i].ToString().LastIndexOf("\\"));
    if (chkSameOutputFolder.Checked == true)
        dstPic = srcPic.Insert(srcPic.LastIndexOf("."),txtSuffix.Text);
    else
        dstPic = txtOutputFolder.Text + "\\" + 
                 srcPic.Substring(srcPic.LastIndexOf("\\") + 1);

    wm.MarkImage(srcPic,dstPic);
    progressBar1.Increment(1);
    statusBarPanel2.Text = "Proecessing Image " + 
      srcPic.Substring(lstFileList.Items[i].ToString().LastIndexOf("\\") + 1);
    Application.DoEvents();
}

Points of Interest

  • I really wanted to put jazzzzyy text in images, something like MS® Word Art. Now, it is very well possible after a few modifications in the source code. I will try to modify the source (hope I'll get the time) so that positions of "Copyright notice" and "logo" are configurable.
  • This example also shows a simple use of the PropertyGrid control.
  • I found a very nice logic to set the default values of the PropertyGrid control. It uses PropertyInfo of System.Reflection. Take a look at the following block of code:
    C#
    PropertyInfo[] props = this.GetType().GetProperties();
    for (int i=0; i<props.Length; i++)
    {
        object[] attrs = 
          props[i].GetCustomAttributes(typeof(DefaultValueAttribute),false);
        if (attrs.Length > 0)
        {
            DefaultValueAttribute attr = (DefaultValueAttribute)attrs[0];
            props[i].SetValue(this,attr.Value,null);
        }
    }
  • get all the properties props.
  • get the custom attribute of each property attrs.
  • get DefaultValueAttribute.
  • set property value.

History

  • 21 June 2005, 1.0 - Tip release of MarkMyImage.
    • Not properly tested, please let me know if you face any error/bug.
    • Copyright notice/watermark notice and watermark logo positions are configurable.
    • Drawback 1, currently the tool supports only JPEG (*.jpg, *.jpeg) and bitmap (*.bmp) images.
  • 15 June 2005, first release of MarkMyImage.
    • Drawback 1, copyright notice/watermark notice and watermark logo positions are hard-coded, hence not configurable.
    • Drawback 2, currently the tool supports only JPEG (*.jpg, *.jpeg) and bitmap (*.bmp) images.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Program Manager
United States United States
Client partner/Technical Architect/Multiple Project Management with over 19+ years of experience in all phases of the software development full & agile life cycle, including technical design, system analysis & programming.

Expertise:
✔ Experienced with large agile onshore/offshore model project(170+ team members).
✔ Innovative ideas and solution to improve development process, execution, test automation, project meta data reporting, etc.
✔ Client relationship, value added service, software development, right process to mitigate risk and ultimately deliver the project on time.
✔ 18+ years of technical "in-depth" knowledge on various programming technologies right from C, C++, Oracle, VB.Net, C#, Windows Workflow 4.0, Windows Communication Foundation, MS SQL Server. Touch of Java, TIBCO BW & BC. The new exciting thing in past few months is 'R' language.
✔ Handling multiple projects, working as client partner to a major bank in Charlotte, North Carolina
✔ Developer of intellectual property of Synechron Inc - Symplus Rule Engine - A rule engine developed using Windows Workflow Foundation 4.0 and Windows Communication Foundation.

Latest/Top stories:

✔ Started a few financial projects around AI(Artificial Intelligence). My new favorite language is R!!!
✔ Executing a few major projects in counter party credit & market risk platform & reg reporting area.
✔ Designed & developed a rule engine named Symplus Rule Engine using WF4.0, WCF, SQL CE 4.0

Comments and Discussions

 
GeneralMy vote of 1 Pin
slava_pvf18-Jun-09 3:43
slava_pvf18-Jun-09 3:43 
GeneralRe: My vote of 1 Pin
YDLU10-Jun-13 8:57
YDLU10-Jun-13 8:57 
Generalexcellent tool Pin
robbiegis9-Jul-08 21:25
robbiegis9-Jul-08 21:25 
GeneralRe: excellent tool Pin
eyedia12-Jul-08 4:05
eyedia12-Jul-08 4:05 
Generalwatermarking images Pin
tauras8120-Sep-07 20:48
tauras8120-Sep-07 20:48 
GeneralGraphics.DrawString Issue Pin
j1mcmahon3-Jan-07 13:04
j1mcmahon3-Jan-07 13:04 
QuestionHow can I watermark anything at runtime? Pin
Nhilesh B29-Apr-06 21:43
Nhilesh B29-Apr-06 21:43 
GeneralNice work,thanks Pin
kellyonlyone17-Feb-06 1:52
sponsorkellyonlyone17-Feb-06 1:52 
GeneralRe: Nice work,thanks Pin
eyedia29-Jan-07 10:39
eyedia29-Jan-07 10:39 
Generalreally cool work Pin
DAVE_ES14-Nov-05 5:10
DAVE_ES14-Nov-05 5:10 
GeneralRe: really cool work Pin
eyedia6-Dec-05 17:17
eyedia6-Dec-05 17:17 
Generalreally cood work Pin
DAVE_ES14-Nov-05 5:08
DAVE_ES14-Nov-05 5:08 
GeneralThanks a lot for your work. Pin
LittleTiger1-Aug-05 15:31
LittleTiger1-Aug-05 15:31 
GeneralRe: Thanks a lot for your work. Pin
eyedia11-Aug-05 3:16
eyedia11-Aug-05 3:16 
GeneralPrintable watermark Pin
William F29-Jun-05 1:31
William F29-Jun-05 1:31 
GeneralRe: Printable watermark Pin
eyedia30-Jun-05 2:03
eyedia30-Jun-05 2:03 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.