C#
watermark
photo editing
programming
image processing

C - Add watermark to the photo by special way

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Adding a watermark is not just about drawing text on top of an image. A good watermark balances visibility, opacity, positioning, and repeatability so the result protects the image without making it unusable.

In C#, the implementation usually comes down to loading the photo, drawing either text or an overlay image with transparency, and saving the result. If you want a "special" watermark effect, the most common variation is a repeated diagonal watermark pattern rather than a single corner label.

Basic Watermark Strategy

The core steps are:

  1. load the original image
  2. create a drawing surface
  3. render watermark content with transparency
  4. save the final image

For a one-off corner watermark, that is enough. For stronger protection, repeat the watermark across the image so it cannot be cropped out easily.

A Simple Text Watermark Example

This example uses System.Drawing, which is most appropriate on Windows-oriented environments:

csharp
1using System.Drawing;
2using System.Drawing.Imaging;
3
4using var image = Image.FromFile("input.jpg");
5using var bitmap = new Bitmap(image);
6using var graphics = Graphics.FromImage(bitmap);
7
8using var font = new Font("Arial", 28, FontStyle.Bold);
9using var brush = new SolidBrush(Color.FromArgb(100, Color.White));
10
11var position = new PointF(bitmap.Width - 220, bitmap.Height - 60);
12graphics.DrawString("Sample", font, brush, position);
13
14bitmap.Save("output.jpg", ImageFormat.Jpeg);

That creates a semi-transparent watermark near the lower-right corner.

A Repeated Diagonal Watermark

For stronger protection, rotate the drawing surface and stamp the text across the image:

csharp
1using System.Drawing;
2using System.Drawing.Imaging;
3
4using var image = Image.FromFile("input.jpg");
5using var bitmap = new Bitmap(image);
6using var graphics = Graphics.FromImage(bitmap);
7
8graphics.TranslateTransform(bitmap.Width / 2f, bitmap.Height / 2f);
9graphics.RotateTransform(-30f);
10
11using var font = new Font("Arial", 26, FontStyle.Bold);
12using var brush = new SolidBrush(Color.FromArgb(60, Color.White));
13
14for (int y = -bitmap.Height; y < bitmap.Height; y += 120)
15{
16    for (int x = -bitmap.Width; x < bitmap.Width; x += 260)
17    {
18        graphics.DrawString("CONFIDENTIAL", font, brush, x, y);
19    }
20}
21
22bitmap.Save("watermarked.jpg", ImageFormat.Jpeg);

This pattern is harder to remove because cropping one corner is no longer enough.

Design Choices That Matter

A watermark should be:

  • visible enough to discourage reuse
  • transparent enough to keep the image usable
  • positioned with intent
  • scaled relative to image size

Hard-coded text size that looks fine on one image may be unreadable or overwhelming on another. For production use, compute font size from image dimensions.

Text Versus Image Watermarks

Text watermarks are easy to generate dynamically. Image watermarks are better when you already have a logo and want consistent branding.

If you use a logo watermark, apply alpha blending and optionally resize the logo before drawing it. The composition logic is the same even though the source is an image instead of text.

Choosing the Output Format

Saving back to JPEG is common for photographs, but remember that JPEG is lossy. If you are watermarking diagrams, screenshots, or assets with sharp edges, PNG may preserve the result better. The watermarking step and the output encoding step are separate decisions, and both affect perceived quality.

Common Pitfalls

  • Using fully opaque watermarks that ruin the image.
  • Hard-coding one font size and ignoring image resolution differences.
  • Placing the watermark only in a corner when the goal is tamper resistance.
  • Relying on System.Drawing in environments where it is not the right runtime choice.
  • Saving repeatedly with lossy compression and degrading the image more than necessary.

Summary

  • A watermark is a compositing task: load, draw with transparency, save.
  • Single-corner text is simple, but repeated diagonal patterns are harder to remove.
  • Opacity, placement, and size should be tuned to the image dimensions.
  • Text and image watermarks follow the same compositing idea.
  • For stronger protection, design the watermark so it cannot be cropped out easily.

Course illustration
Course illustration

All Rights Reserved.