---
title: "Colored Text"
canonical: https://www.graphicsmill.com/samples/Text/EnhancedText/ColoredText_cs
product: "Graphics Mill"
source: "Text/EnhancedText/ColoredText.cs"
---

# Colored Text

Renders formatted, multi-colored text onto a bitmap.

## Instruction

This code demonstrates how to render formatted text with different styles (such as color, bold, italic, font, etc.) to a bitmap.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
// Here one may find all possible tags
// https://www.graphicsmill.com/docs/gm/advanced-formatted-text.htm

using (var bitmap = new Bitmap(600, 400, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255, 255)))
using (var graphics = bitmap.GetGraphics())
{
    var brush = new SolidBrush(RgbColor.Black);

    var dummyText = @"Lorem ipsum dolor sit <span style='color:red;'>amet</span>, consectetur adipiscing elit. " +
        @"<span style='bold:true;underline:true;color:rgb(0,0,255)'>Cras</span> elementum quam ac nisi varius gravida. Mauris ornare, " +
        @"<span style='font-name:Times New Roman;font-size:60pt;pen-color:green;pen-width:1px;color:yellow;'>dolor</span> et scelerisque " +
        @"volutpat, <span style='italic:true;color:gray;'>enim urna commodo odio, <span style='color:green;'>consequat</span> fermentum sem arcu</span> sit amet nisl. " +
        @"Aliquam tincidunt id neque in gravida. Mauris mollis est vulputate suscipit facilisis.";

    var boundedText = new BoundedText(dummyText, graphics.CreateFont("Verdana", 26f), brush)
    {
        Rectangle = new System.Drawing.RectangleF(20f, 20f, 560f, 360f),
    };

    graphics.DrawText(boundedText);

    bitmap.Save("ColoredText.png");
}
```

## Explanation

The code:

- Creates a `Bitmap` with specified dimensions and a white background color.
- Initializes the graphics context to draw on the bitmap.
- Defines a string with HTML-style tags for styling parts of the text (e.g., red color, bold, italic, font customization).
- Uses `BoundedText` to specify the formatted text, applying the styles from the string.
- Draws the formatted text onto the bitmap.
- Saves the resulting image as a PNG file with the name `ColoredText.png`.

## Tags

- [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

## Output

- [ColoredText.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ColoredText_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.BoundedText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_BoundedText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.BoundedText.Rectangle](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_BoundedText_Rectangle.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.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
