Reflected Text

Text Drawing Gradient Art Text

Exhibits a possible technique for implementing a mirrored text effect.

Сode Snippet

using (var bitmap = new Bitmap(500, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var gr = bitmap.GetAdvancedGraphics())
{
    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.GetAdvancedGraphics())
    {
        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");
}

Output

ReflectedText.png

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog