惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
B
Blog
WordPress大学
WordPress大学
Project Zero
Project Zero
P
Palo Alto Networks Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
T
Tailwind CSS Blog
Forbes - Security
Forbes - Security
F
Full Disclosure
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News: Ask HN
Hacker News: Ask HN
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
G
Google Developers Blog
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
O
OpenAI News
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
IT之家
IT之家
U
Unit 42
腾讯CDC
S
Security Affairs
C
Cisco Blogs
Schneier on Security
Schneier on Security
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss

博客园 - 不做懒人

一个用户登录验证的类 用C#实现C/S模式下软件自动在线升级[转载] 实现.NET应用程序的自动更新[转载] 高效 Ini文件访问类(C#编写,用于Windows Mobile) 终于得空,写两句了...... CSS+DIV技巧两则(居中,高度自适应) - 不做懒人 - 博客园 正则表达式替换字符串的一个技巧 --- 可用于关键词变红色 - 不做懒人 下载:Visual Studio 2008 SDK VS2008——软件开发更智能 08年了,准备写点东西了~~ 想设计一个简单的RSS在线阅读程序,欢迎大伙提供意见 [转载]在SQL SERVER如何添加数据用户 大量并发访问xml和数据库的效率问题 Asp.net中下拉框绑定值的怪现象。 字符串数组的一些处理方法总结 [转载]知识不一定会带来金钱,挣钱靠的是能力 [转载]2006年优秀网页UI设计风格剖析 [转载]网页设计技巧系列之文本排版 [转载]网页布局的四种基本型与十二种混合型
C#实现“新华网头条的图片新闻”
不做懒人 · 2008-07-26 · via 博客园 - 不做懒人

先发几个图片,看一下直观的效果。

这个源码,大多是网上的一个兄弟写的。俺只是整理,稍微修改了一下,更通用而已。再次对他表示感谢。

源码如下:

......

using System.Drawing.Drawing2D;

......

 private void MakeImg(string text, int width, int height, Color color, string outPath)
        {
            FontFamily fontFamily = new FontFamily("文鼎特粗黑简");
            GraphicsPath path = new GraphicsPath();

            path.AddString(text, fontFamily, (int)FontStyle.Regular, 47, new Point(-9, 0), new StringFormat());  //字体大小为60 ,根据要生成图片的高度而定

            PointF[] dataPoints = path.PathPoints;  //获取路径的点信息

            byte[] pTypes = path.PathTypes;    //获取路径的点类型信息

            double widthpara = (double)width /( (height + 0.5) * text.Length);    //计算宽度参数
            Matrix matrix = new Matrix((float)widthpara, 0.0f, 0.0f, 1f, 0.0f, 0.0f);  //将文本在水平方向上缩小,在垂直方向上不变

            matrix.TransformPoints(dataPoints); //对points数据中的每一个成员进行矩形运算

            GraphicsPath newpath = new GraphicsPath(dataPoints, pTypes); //根据计算后的点重新构造路径

            Bitmap bmap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bmap);
            g.Clear(Color.White);   //设置图片的背景
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;   //设置文本输出质量
            g.SmoothingMode = SmoothingMode.AntiAlias;
            SolidBrush redBrush = new SolidBrush(color);

            g.FillPath(redBrush, newpath);  //填充路径
            bmap.Save(outPath, System.Drawing.Imaging.ImageFormat.Png);
            g.Dispose();
            redBrush.Dispose();
        }

生成的时候,调用此函数即可。

注:您可以在这个网站看到效果(http://www.cetfj.com/