This documentation is for the old version. Go to the latest Graphics Mill docs

Drawing Text with Effects

Text with effects are looking more striking and eye catching than plain caption. It is especially actual in web graphics. This article demonstrates how to apply some effects on text.

Let's start with a shadow effect. To create realistic shadow we should draw plain text on transparent bitmap and apply Shadow transform at it. As a result we will get something like this:

Shadowed text

This code demonstrates how to accomplish it:

Visual Basic
'Create bitmap with transparent background
Dim bitmapText As New Aurigma.GraphicsMill.Bitmap(150, 30, _
    Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)

Dim graphics As System.Drawing.Graphics = bitmapText.GetGdiplusGraphics()

'Set text output properties
Dim font As New System.Drawing.Font("Arial", 22, FontStyle.Bold)
Dim brush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)

'Draw text
graphics.DrawString("Sample text", font, brush, 5, 5)

'Apply shadow effect on text
bitmapText.Transforms.Shadow(Aurigma.GraphicsMill.RgbColor.Black, 2, 2, 4, False)

'Apply glow effect on text
'bitmapText.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Blue, 1, 4, False)

'Convert to 24 bit images (merge alpha channel with white background)
bitmapText.Channels.DiscardAlpha(Aurigma.GraphicsMill.RgbColor.White)
C#
//Create bitmap with transparent background
Aurigma.GraphicsMill.Bitmap bitmapText = new Aurigma.GraphicsMill.Bitmap(150, 30, 
    Aurigma.GraphicsMill.PixelFormat.Format32bppArgb);

System.Drawing.Graphics graphics = bitmapText.GetGdiplusGraphics();

//Set text output properties
System.Drawing.Font font = new System.Drawing.Font("Arial", 22, FontStyle.Bold);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

//Draw text
graphics.DrawString("Sample text", font, brush, 5, 5);

//Apply shadow effect on text
bitmapText.Transforms.Shadow(Aurigma.GraphicsMill.RgbColor.Black, 2, 2, 4, false);

//Apply glow effect on text
//bitmapText.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Blue, 1, 4, false);

//Convert to 24 bit images (merge alpha channel with white background)
bitmapText.Channels.DiscardAlpha(Aurigma.GraphicsMill.RgbColor.White);

As usual you need not a separate text label, but want to draw it on some existing image. So let improve this code example by drawing the label containing a shadowed text at an image. An example of it you can see at this figure:

Image with shadowed text

Use the following code to get this result:

Visual Basic
'Create bitmap with transparent background
Dim bitmapText As New Aurigma.GraphicsMill.Bitmap(150, 30, _
    Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)

Dim graphics As System.Drawing.Graphics = bitmapText.GetGdiplusGraphics()

'Set text output properties
Dim font As New System.Drawing.Font("Arial", 22, FontStyle.Bold)
Dim brush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)

'Draw text
graphics.DrawString("Sample text", font, brush, 10, 5)

'Apply shadow effect on text
bitmapText.Transforms.Shadow(Aurigma.GraphicsMill.RgbColor.Black, 2, 2, 4, False)

'Apply glow effect on text
'bitmapText.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Blue, 1, 4, False)

'Create bitmap object which contains image on which we want to draw text
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("C:\landscape.jpg")

'Draw text with shadow or glow on bitmap
bitmapText.Draw(bitmap, 0, 0, bitmapText.Width, bitmapText.Height, _
    Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, _
    Aurigma.GraphicsMill.Transforms.InterpolationMode.LowQuality)
C#
//Create bitmap with transparent background
Aurigma.GraphicsMill.Bitmap bitmapText = new Aurigma.GraphicsMill.Bitmap(150, 30, 
    Aurigma.GraphicsMill.PixelFormat.Format32bppArgb);

System.Drawing.Graphics graphics = bitmapText.GetGdiplusGraphics();

//Set text output properties
System.Drawing.Font font = new System.Drawing.Font("Arial", 22, FontStyle.Bold);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

//Draw text
graphics.DrawString("Sample text", font, brush, 10, 5);

//Apply shadow effect on text
bitmapText.Transforms.Shadow(Aurigma.GraphicsMill.RgbColor.Black, 2, 2, 4, false);

//Apply glow effect on text
//bitmapText.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Blue, 1, 4, false);

//Create bitmap object which contains image on which we want to draw text
Aurigma.GraphicsMill.Bitmap bitmap = 
    new Aurigma.GraphicsMill.Bitmap(@"C:\landscape.jpg");

//Draw text with shadow or glow on bitmap
bitmapText.Draw(bitmap, 0, 0, bitmapText.Width, bitmapText.Height, 
    Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, 
    Aurigma.GraphicsMill.Transforms.InterpolationMode.LowQuality);

You can use not only shadow effect. For example, you can use the Glow method instead of Shadow:

Glow text

Yet another effect you can use is a 3D text emulation. This can eaily be done by drawing the same text twice—the second time with a small offset, say, one pixel.

3D text

The code below shows how to create such an effect.

Visual Basic
'Create bitmap
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
Aurigma.GraphicsMill.RgbColor.White, 150, 30, _
Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)

Dim graphics As System.Drawing.Graphics = bitmap.GetGdiplusGraphics()

'Set text properties
Dim font As New System.Drawing.Font("Arial", 22, FontStyle.Bold)

'Set background text properties
Dim brush As New System.Drawing.SolidBrush(System.Drawing.Color.DarkRed)

'Draw background text
graphics.DrawString("Sample text", font, brush, 6, 6)

'Set foreground text properties
brush.Color = System.Drawing.Color.Red

'Draw foreground text
graphics.DrawString("Sample text", font, brush, 5, 5)
C#
//Create bitmap
Aurigma.GraphicsMill.Bitmap bitmap = new
    Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.RgbColor.White,
    150, 30, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb);

System.Drawing.Graphics graphics = bitmap.GetGdiplusGraphics();

//Set text properties
System.Drawing.Font font = new System.Drawing.Font("Arial", 22,
    FontStyle.Bold);

//Set background text properties
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(
    System.Drawing.Color.DarkRed);

//Draw background text
graphics.DrawString("Sample text", font, brush, 6, 6);

//Set foreground text properties
brush.Color = System.Drawing.Color.Red;

//Draw foreground text
graphics.DrawString("Sample text", font, brush, 5, 5);

So feel free to experiment.