Reflected Text
View as MarkdownExhibits a possible technique for implementing a mirrored text effect.
Code Snippet
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");
}
Output
ReflectedText.png
Used APIs
- Aurigma.GraphicsMill.Bitmap.GetGraphics
- Aurigma.GraphicsMill.Bitmap.Transforms
- Aurigma.GraphicsMill.Color.ScaleAlpha(Single)
- Aurigma.GraphicsMill.Drawing.ColorStop
- Aurigma.GraphicsMill.Drawing.ColorStop.Color
- Aurigma.GraphicsMill.Drawing.ColorStop.Exponent
- Aurigma.GraphicsMill.Drawing.ColorStop.Position
- Aurigma.GraphicsMill.Drawing.GradientBrush.ColorStops
- Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)
- Aurigma.GraphicsMill.Drawing.Graphics.DpiX
- Aurigma.GraphicsMill.Drawing.Graphics.DpiY
- Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,Single,Single)
- Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)
- Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry
- Aurigma.GraphicsMill.Drawing.Graphics.Transform
- Aurigma.GraphicsMill.Drawing.LinearGradientBrush
- Aurigma.GraphicsMill.Drawing.LinearGradientBrush.EndPoint
- Aurigma.GraphicsMill.Drawing.LinearGradientBrush.StartPoint
- Aurigma.GraphicsMill.Drawing.PlainText
- Aurigma.GraphicsMill.Drawing.PlainText.Position
- Aurigma.GraphicsMill.Drawing.Text.Brush
- Aurigma.GraphicsMill.Drawing.Text.GetBlackBox(FontRegistry,Single,Single)
- Aurigma.GraphicsMill.Transforms.FlipType
- Aurigma.GraphicsMill.Transforms.InterpolationMode
- Aurigma.GraphicsMill.Transforms.Matrix
- Aurigma.GraphicsMill.Transforms.Matrix.CreateFromProjectivePoints(PointF[],PointF[])
- Aurigma.GraphicsMill.TransformsProvider.ApplyMatrix(Matrix,Color,InterpolationMode)
- Aurigma.GraphicsMill.TransformsProvider.Flip(FlipType)