Jump to content



Photo

[C#] Drawing outline text


  • Please log in to reply
32 replies to this topic

#1 yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 10 January 2005 - 10:03

Hello,
I want to draw an outlined text using C#.Net. How can I do it? I think I need to use GDI but how exactly? All I know is how to draw a normal text.

Thanks in advance for your help :)


#2 kjordan2001

kjordan2001

    Mystery Solver

  • Tech Issues Solved: 1
  • Joined: 27-May 02

Posted 10 January 2005 - 17:05

Just draw a lot of lines: http://csharpcomputi...ls/Lesson15.htm

Or if you want to get really fancy, draw lines that form Besier curves for each letter and that way it can go at any angle.

#3 OP yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 10 January 2005 - 20:46

Thanks - but I think it is too complicated to me :blush: Nevermind - I've decided to do something else after all - sorry :rolleyes:

#4 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 11 January 2005 - 07:35

It's pretty easy.

From Windows Forms Programming in C# by Chris Sells
GraphicsPath GetStringPath( string s, float dpi, RectangleF rect, Font font, StringFormat format)
{
    GraphicsPath path = new GraphicsPath();
    // Convert font size into appropriate coordinates
    float emSize = dpi * font.SizeInPoints / 72;
    path.AddString(s, font.FontFamily, (int)font.Style, emSize, rect, format);

    return path;
}

void Form_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    string s = "Outline";
    RectangleF rect = this.ClientRectangle;
    Font font = this.Font;
    StringFormat format = StringFormat.GenericTypographic;
    float dpi = g.DpiY;
    using( GraphicsPath = GetStringPath(s, dpi, rect, font, format) )
    {
        g.DrawPath(Pens.Black, path);
    }
}


#5 OP yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 11 January 2005 - 08:51

Works nice :cool: Thanks a lot weenur :laugh:

But I was thinking more of something like this:
outline.png
I want it to have an inner white color and a shadow. Do you think it is possible ?

#6 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 11 January 2005 - 16:37

I want it to have an inner white color and a shadow. Do you think it is possible ?

It's possible.

In the paint event.
  	Graphics g = e.Graphics;
  	string s = "Outline";
  	RectangleF rect = this.ClientRectangle;
  	Font font = this.Font;
  	StringFormat format = StringFormat.GenericTypographic;
  	float dpi = g.DpiY;
  	using( GraphicsPath path = GetStringPath(s, dpi, rect, font, format) )
  	{	
    g.SmoothingMode = SmoothingMode.AntiAlias;
    RectangleF off = rect;
    off.Offset( 5, 5 );
    using( GraphicsPath offPath = GetStringPath(s, dpi, off, font, format) )
    {
    	Brush b = new SolidBrush(Color.FromArgb(100, 0, 0, 0));
    	g.FillPath(b, offPath);
    	b.Dispose();
    }
    g.FillPath(Brushes.White, path);
    g.DrawPath(Pens.Black, path);
  	}

Edited by weenur, 11 January 2005 - 16:46.


#7 OP yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 11 January 2005 - 17:17

:laugh: Thanks a lot weenur - that's really close :D Can I make the shadow even more smooth? Is there a way I can control the shadow width?

#8 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 11 January 2005 - 17:53

:laugh: Thanks a lot weenur - that's really close  :D Can I make the shadow even more smooth? Is there a way I can control the shadow width?

View Post

You want that with ice cream? :p

You basically want a blur on the shadow, no?

Edited by weenur, 11 January 2005 - 18:24.


#9 OP yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 11 January 2005 - 18:41

Yes - I'm really sorry that I bother you :blush: :rolleyes: I didn't mean to do it. I was too rude :unsure: it's not urgent so if you have time I'll apprreciate your answer.

#10 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 11 January 2005 - 22:16

Yes - I'm really sorry that I bother you  :blush:  :rolleyes: I didn't mean to do it. I was too rude  :unsure:  it's not urgent so if you have time I'll apprreciate your answer.

View Post

No sweat. I'm just giving you grief. ;)

I should be able to have an example for you as soon as I get some time. I also need to figure out how to convert a region to a bitmap. <anyone?>

#11 OP yyy

yyy

    Neowinian

  • Joined: 15-July 04

Posted 11 January 2005 - 22:30

Actually I've found this: http://www.bobpowell...pshadowtext.htm but it uses another method than yours.

Anyway, don't hurry. I'm not sure if I'll use it eventually or not. I'll do another thing instead :)

#12 _Pablo

_Pablo

    Have a nice day.

  • Joined: 01-December 01

Posted 11 January 2005 - 23:34

No sweat. I'm just giving you grief. ;)

I should be able to have an example for you as soon as I get some time. I also need to figure out how to convert a region to a bitmap. <anyone?>

View Post


A Region of what?

#13 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 11 January 2005 - 23:54

I'm converting the GraphicsPath to a Region, and then from a Region to a Bitmap to perform raster operations on it. I see what Bob is doing. That's cool. The guy is a guru. I was actually going to do a gaussian blur on the shadow and make it adjustable. I'm just drawing a blank on how to make a Bitmap from a Region.

Region class

#14 _Pablo

_Pablo

    Have a nice day.

  • Joined: 01-December 01

Posted 12 January 2005 - 00:08

I'm converting the GraphicsPath to a Region, and then from a Region to a Bitmap to perform raster operations on it. I see what Bob is doing. That's cool. The guy is a guru. I was actually going to do a gaussian blur on the shadow and make it adjustable. I'm just drawing a blank on how to make a Bitmap from a Region.

Region class

View Post


Yes but a Region is simply that - a region. So to turn it into a Bitmap you need to use the region on a Bitmap e.g. Create a new Bitmap of the appropriate dimensions then use Graphics.FillRegion with a suitable Brush. Or am I missing something?

#15 azcodemonkey

azcodemonkey

    Neowinian Senior

  • Joined: 19-March 02

Posted 12 January 2005 - 02:11

Yes but a Region is simply that - a region. So to turn it into a Bitmap you need to use the region on a Bitmap e.g. Create a new Bitmap of the appropriate dimensions then use Graphics.FillRegion with a suitable Brush. Or am I missing something?

View Post


See... that's what I couldn't remember. :D Thanks. It's been a while since I've done any GDI/+ to any extent.



Click here to login or here to register to remove this ad, it's free!