• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 825
  • Last Modified:

Drawing a font with a different outline colour

Below is an example of the code I'm using to draw a font onto an existing gif image, which works fine:

Bitmap bmpImage = new Bitmap(@"C:\bg.gif");
Graphics image = Graphics.FromImage(bmpImage);
image.SmoothingMode = SmoothingMode.AntiAlias;
image.TextRenderingHint = TextRenderingHint.AntiAlias;
Font someText = new Font("Arial", 15, FontStyle.Bold);
image.DrawString("Test", someText, Brush.Black, new Point(2, 2));

However, I also want a two pixel thick outline around the font in a different colour.  How can I achieve this?

Thanks in advance.
0
redstar_play247
Asked:
redstar_play247
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Rectangle rect = new Rectangle(x, y, width, height);
Pen pen = new Pen(Color.Red, 2);

image.DrawRectangle(pen, rect);

pen.Dispose();

Bob
0
 
gregoryyoungCommented:
umm Bob not to be critical but thats a rectangle :) just giving you a hard time ....

the easiest way to do this is to draw the string multiple times ...



image.DrawString("Test", someText, Brush.Red, new Point(1, 2));
image.DrawString("Test", someText, Brush.Red, new Point(3, 2));
image.DrawString("Test", someText, Brush.Red, new Point(2, 1));
image.DrawString("Test", someText, Brush.Red, new Point(2, 3));
image.DrawString("Test", someText, Brush.Black, new Point(2, 2));
0
 
gregoryyoungCommented:
naturally you can loop this to do as many pixels as you want ...

also you can do drop shadows in the same way.

Cheers,

Greg
0
 
Bob LearnedCommented:
So, it's your way, my way, or the highway?  =:)

Bob
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now