Drawing a font with a different outline colour

Posted on 2005-05-12
Last Modified: 2013-12-03
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.
Question by:redstar_play247
    LVL 96

    Expert Comment

    by:Bob Learned
    Rectangle rect = new Rectangle(x, y, width, height);
    Pen pen = new Pen(Color.Red, 2);

    image.DrawRectangle(pen, rect);


    LVL 37

    Accepted Solution

    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));
    LVL 37

    Expert Comment

    naturally you can loop this to do as many pixels as you want ...

    also you can do drop shadows in the same way.


    LVL 96

    Expert Comment

    by:Bob Learned
    So, it's your way, my way, or the highway?  =:)


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now