---
title: "Reflected Text"
canonical: https://www.graphicsmill.com/samples/Text/EnhancedText/ReflectedText_cs
product: "Graphics Mill"
source: "Text/EnhancedText/ReflectedText.cs"
---

# Reflected Text

Exhibits a possible technique for implementing a mirrored text effect.

## Instruction

This code generates an image with reflected text by using transformations and custom drawing styles.

## Usings

```csharp
using System.Drawing;
using Aurigma.GraphicsMill.Drawing;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap(500, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var gr = bitmap.GetGraphics())
{
    var textPos = new System.Drawing.Point(50, 100);

    var text = new PlainText("<span style=\"tracking:50\">TEXT SAMPLE</span>", gr.CreateFont("Arial", 50));

    // Here it’s more convenient to define text position via matrix transform
    gr.Transform.Translate(textPos.X, textPos.Y);

    var bbox = text.GetBlackBox(gr.FontRegistry, gr.DpiX, gr.DpiY);

    // Draw original text
    gr.DrawText(text);

    // Parameters for reflected text widening
    const float leftExtension = 20;
    const float rightExtension = 20;

    // We need an additional bitmap
    using (var reflectedTextBitmap = new Bitmap((int)(bbox.Width + leftExtension + rightExtension), (int)bbox.Height, PixelFormat.Format32bppArgb, RgbColor.Transparent))
    using (var reflectedGraphics = reflectedTextBitmap.GetGraphics())
    {
        var brush = new LinearGradientBrush()
        {
            StartPoint = new System.Drawing.PointF(0, 0),
            EndPoint = new System.Drawing.PointF(0, bbox.Height),
            ColorStops = new[]
            {
                new ColorStop() { Color = RgbColor.Transparent, Position = 0, Exponent = 1.0f },
                new ColorStop() { Color = RgbColor.Black.ScaleAlpha(0.8f), Position = 1 },
            },
        };

        text.Brush = brush;
        text.Position = new System.Drawing.PointF(leftExtension, -bbox.Top);

        // Draw the same with with different brush and position
        reflectedGraphics.DrawText(text);

        var srcPoints = new[]
        {
            new System.Drawing.PointF(bbox.Left, bbox.Bottom),
            new System.Drawing.PointF(bbox.Right, bbox.Bottom),
            new System.Drawing.PointF(bbox.Right, bbox.Height),
            new System.Drawing.PointF(bbox.Left, bbox.Height),
        };

        var dstPoints = new[]
        {
            new System.Drawing.PointF(bbox.Left - leftExtension, bbox.Bottom),
            new System.Drawing.PointF(bbox.Right + rightExtension, bbox.Bottom),
            new System.Drawing.PointF(bbox.Right, bbox.Height),
            new System.Drawing.PointF(bbox.Left, bbox.Height),
        };

        // Use projective matrix transform for text widening
        var projectiveMatrix = Aurigma.GraphicsMill.Transforms.Matrix.CreateFromProjectivePoints(srcPoints, dstPoints);

        reflectedTextBitmap.Transforms.ApplyMatrix(projectiveMatrix, RgbColor.Transparent, InterpolationMode.Medium);
        reflectedTextBitmap.Transforms.Flip(FlipType.Horizontal);

        gr.DrawImage(reflectedTextBitmap, -leftExtension * 2, bbox.Bottom + 3);
    }

    bitmap.Save("ReflectedText.png");
}
```

## Explanation

The code:

- Creates a `Bitmap` object with a white background (`RgbColor.White`) and a defined size (500x200).
- Initializes an `AdvancedGraphics` object to handle drawing on the bitmap.
- Defines the text "TEXT SAMPLE" with 50pt Arial font and applies tracking (letter-spacing) of 50 units.
- The text position is set using a transformation matrix for translation, and its bounding box is calculated to get its dimensions.
- The original text is drawn first on the bitmap at the specified position.
- For the reflected text, a new `Bitmap` object is created with transparent background and dimensions that fit the extended text width.
- A `LinearGradientBrush` is used to fill the reflected text with a gradient, starting with transparency at the top and fading to black with some alpha at the bottom.
- The reflected text is drawn on the new bitmap using the modified brush and position.
- The projective transformation is applied to widen the reflected text, and the bitmap is horizontally flipped.
- The reflected text is drawn on the original image at the appropriate position.
- The final result is saved as a PNG file (`ReflectedText.png`).

## Tags

- [Art Text](<https://www.graphicsmill.com/samples/tags/art-text_md>): Creating artistic text
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Gradient](<https://www.graphicsmill.com/samples/tags/gradient_md>): Using gradient brushes and fills
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text

## Output

- [ReflectedText.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ReflectedText_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.Transforms](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md>)
- [Aurigma.GraphicsMill.Color.ScaleAlpha(Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Color_ScaleAlpha_1_7a94462e.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ColorStop](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ColorStop.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ColorStop.Color](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ColorStop_Color.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ColorStop.Exponent](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ColorStop_Exponent.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ColorStop.Position](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ColorStop_Position.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GradientBrush.ColorStops](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GradientBrush_ColorStops.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.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_3_b9413d4f.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.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_Transform.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LinearGradientBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_LinearGradientBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LinearGradientBrush.EndPoint](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_LinearGradientBrush_EndPoint.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LinearGradientBrush.StartPoint](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_LinearGradientBrush_StartPoint.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.Text.GetBlackBox(FontRegistry,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Text_GetBlackBox_3_185e8a92.htm.md>)
- [Aurigma.GraphicsMill.Transforms.FlipType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_FlipType.htm.md>)
- [Aurigma.GraphicsMill.Transforms.InterpolationMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_InterpolationMode.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Matrix](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Matrix.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Matrix.CreateFromProjectivePoints(PointF\[\],PointF\[\])](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Matrix_CreateFromProjectivePoints_2_a6854ac1.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.ApplyMatrix(Matrix,Color,InterpolationMode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_ApplyMatrix_3_dbff41c3.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.Flip(FlipType)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_Flip_1_e191919c.htm.md>)
