一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net中C#实现图片加带描边字体例子

时间:2015-03-25 编辑:简简单单 来源:一聚教程网

效果如下

asp.net中C#实现图片加带描边字体例子

代码如下

private Image loadFont(string pa)
{
Image bmap;
bmap = Image.FromFile(pa);

Graphics g = Graphics.FromImage(bmap);//在Image对象上创建Graphics对象

g.SmoothingMode = SmoothingMode.AntiAlias;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
GraphicsPath myPath = new GraphicsPath();

string stringText = this.textBox1.Text.Trim();
string Font = "";//字体
this.comboBox1.Invoke(new EventHandler(delegate
{
    Font = this.comboBox1.Text;
}));
FontFamily family = new FontFamily(Font);
int fontStyle = (int)FontStyle.Bold;
int emSize = (int)numericUpDown3.Value;//字体大小
Point origin = new Point(10, 10);
StringFormat format = StringFormat.GenericDefault;
Brush bru = new SolidBrush(Color.FromArgb(241, 027, 039));
myPath.AddString(stringText,
    family,
    fontStyle,
    emSize,
    origin,
    format);

g.FillPath(bru, myPath);
g.DrawPath(new Pen(Color.White, (float)numericUpDown1.Value), myPath);
//bmap.Save(@"d:/test.jpg");//将Image图片保存到本地
return bmap;
}

获取系统所有的字体

InstalledFontCollection MyFont = new InstalledFontCollection();
FontFamily[] MyFontFamilies = MyFont.Families;
int Count = MyFontFamilies.Length;
for (int i = 0; i < Count; i++)
{
    this.comboBox1.Items.Add(MyFontFamilies[i].Name);
}

热门栏目