Wednesday, February 06, 2008

 My previous job required a bit of multimedia programming and involved the use of a lot of different graphics techniques. One day we ran across a bit of code to give drawn text either an outerglow or an outline around it. It turns outs to be much simpler to do than I previously thought and only goes to show that you can always learn a new trick. The original project can be downloaded from FancyText.

The basic concept here is drawing the text multiple times in slightly different locations in one color with the alpha channel set to around 15 to 25. Next you print the original text centered back over the glowing text. The results look excellent. When I get the time I will create a label style control based on this code and post it. 

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.ComponentModel;
   4:  using System.Data;
   5:  using System.Drawing;
   6:  using System.Text;
   7:  using System.Windows.Forms;
   8:  using System.Drawing.Drawing2D;
   9:  using System.Drawing.Text;
  10:   
  11:  namespace OutGlowText
  12:  {
  13:      public partial class MainForm : Form
  14:      {
  15:          string OutStr = "Glowing Text";
  16:          int BlurAmt = 9;
  17:   
  18:          public MainForm()
  19:          {
  20:              InitializeComponent();
  21:          }
  22:   
  23:          private void MainForm_Load(object sender, EventArgs e)
  24:          {
  25:              this.BackColor = Color.Black;
  26:          }
  27:   
  28:          protected override void OnPaint(PaintEventArgs e)
  29:          {
  30:              Graphics g = e.Graphics;
  31:              Brush br = new SolidBrush(Color.FromArgb(15, Color.White));
  32:   
  33:              g.SmoothingMode = SmoothingMode.HighQuality;
  34:              g.InterpolationMode = InterpolationMode.HighQualityBilinear;
  35:              g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
  36:   
  37:              for (int x = 0; x <= BlurAmt; x++)
  38:              {
  39:                  for (int y = 0; y <= BlurAmt; y++)
  40:                  {
  41:                      g.DrawString(OutStr, new Font("Arial", 48,FontStyle.Bold),br, new Point(x, y));
  42:                  }
  43:              }
  44:              
  45:              g.DrawString(OutStr, 
  46:                           new Font("Arial", 48,FontStyle.Bold ), 
  47:                           Brushes.Blue, 
  48:                           new Point(BlurAmt /2, BlurAmt/2));
  49:   
  50:              base.OnPaint(e);
  51:          }
  52:   
  53:      }
  54:  }
 
kick it on DotNetKicks.com
posted on Wednesday, February 06, 2008 6:32:42 PM (Eastern Standard Time, UTC-05:00)  #    Comments [3]