不鳥萬如一的各種垃圾彙總 2018-01-24
做了个艺术字在线制作网站,整理一下技术代码
System.Drawing.Text.PrivateFontCollection FM = new PrivateFontCollection();
FM.AddFontFile(Server.MapPath("字体文件路径"));
FontFamily FML = FM.Families[0];这样我们就可以直接读取字体了
我们可以通过
FontStyle fontStyle = FontStyle.Regular;<br />fontStyle |= FontStyle.Italic;<br />fontStyle |= FontStyle.Underline;<br /><br />...
fontStyle -= FontStyle.Regular;
fontStyle |= FontStyle.Bold;
Font font = new Font(FML, 字体大小, fontStyle, GraphicsUnit.Point);
这个我们可以设置字体加粗,斜体,下划线的功能
Color color = ColorTranslator.FromHtml("#ff0000"); //设置字体颜色Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
//这里设置图片质量
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.AssumeLinear;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
RectangleF rect = new RectangleF(1, 1, width, height);
SolidBrush brush = new SolidBrush(color);//绘制图片
g.DrawString("这里要生成的文字", font, brush, rect);
brush.Dispose();<br /><br /><br /><br />MemoryStream msBG = new MemoryStream();//保存图片
image.Save(msBG, ImageFormat.Png);
最后不要忘了释放资源
FML.Dispose(); font.Dispose(); g.Dispose(); image.Dispose();<br /><br />
return File(msBG.ToArray(), "image/png");
具体的demo演示大家可以去我网站上查看 http://www.shiwusui.com
使用 CSS3,网页设计师可以使用他/她喜欢的任何字体。只需简单的将字体文件包含在网站中,它会自动下载给需要的用户。在新的 @font-face 规则中,您必须首先定义字体的名称,然后指向该字体文件。