---
title: "Colored Watermark"
canonical: https://www.graphicsmill.com/samples/Text/EnhancedText/ColoredWatermark_cs
product: "Graphics Mill"
source: "Text/EnhancedText/ColoredWatermark.cs"
---

# Colored Watermark

Demonstrates how to apply a colored watermark to an image using a tiling brush with text rendering.

## Instruction

This code demonstrates how to apply a colored watermark to an image using a tiling brush with text rendering.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap("Venice.jpg"))
using (var gr = bitmap.GetGraphics())
{
    var fontSize = UnitConverter.ConvertPixelsToUnits(bitmap.DpiY, bitmap.Height, Unit.Point) / 20.0f;

    var brush = new TilingBrush(600, 300, bitmap.DpiX, bitmap.DpiY);

    var formattedString = @"<span style='color:red'>Colored</span><br/>
    <span style='color:rgb(0, 0, 0, 0);pen-color:rgb(200, 200, 200, 255);pen-width:5pt'>watermark</span>";

    var text = new PlainText(formattedString, gr.CreateFont("Arial", fontSize))
    {
        Position = new System.Drawing.Point(10, 100),
        Brush = null,
    };

    brush.Graphics.FontRegistry = FontRegistry.Installed;
    brush.Graphics.DrawText(text);
    brush.Transform = new System.Drawing.Drawing2D.Matrix();
    brush.Transform.Rotate(45);

    gr.Opacity = 0.5f;
    gr.FillRectangle(brush, 0, 0, bitmap.Width, bitmap.Height);

    bitmap.Save("ColoredWatermark.jpg");
}
```

## Explanation

The code:

- Loads an image (`Venice.jpg`) into a `Bitmap` object.
- Initializes the graphics context for drawing on the bitmap.
- Calculates a font size based on the bitmap's DPI and height.
- Creates a `TilingBrush` with specified dimensions and DPI for tiling.
- Defines a formatted string with HTML-style tags for styling the watermark text (e.g., color, pen-width, and transparency).
- Creates a `PlainText` object with the formatted string and font, setting its position and brush (which is null for the text).
- Registers fonts and draws the text with the tiling brush applied at a 45-degree angle.
- Sets the graphics opacity to 0.5 for a semi-transparent effect.
- Fills the entire image with the watermark text using the tiling brush.
- Saves the modified image as a new file (`ColoredWatermark.jpg`).

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Formatted Text](<https://www.graphicsmill.com/samples/tags/formatted-text_md>): XML-based formatted text syntax
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text

## Input

- [Venice.jpg](<https://www.graphicsmill.com/samples/Text/compiled/Debug/Venice_jpg>) (preview)

## Output

- [ColoredWatermark.jpg](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ColoredWatermark_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontRegistry](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontRegistry.Installed](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontRegistry_Installed.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillRectangle(Brush,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillRectangle_5_2d30ad96.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.Opacity](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_Opacity.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText.Position](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_PlainText_Position.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.Brush](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_Brush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_TilingBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush.Graphics](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_TilingBrush_Graphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_TilingBrush_Transform.htm.md>)
- [Aurigma.GraphicsMill.Unit](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Unit.htm.md>)
- [Aurigma.GraphicsMill.UnitConverter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_UnitConverter.htm.md>)
- [Aurigma.GraphicsMill.UnitConverter.ConvertPixelsToUnits(Single,Int32,Unit)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_UnitConverter_ConvertPixelsToUnits_3_d5fc159a.htm.md>)
