C#给图片增加文字实例代码


本文摘自PHP中文网,作者零下一度,侵删。

业务需要动态给图片增加文字(书本的封面图片),修改字体大小、字体、颜色、控制位置

测试代码:

1

1             string path = @"E:\cover.png"; 2  3             Bitmap bmp = new Bitmap(path); 4             Graphics g = Graphics.FromImage(bmp); 5             String str = "贤愚经"; 6             Font font = new Font("仿宋_GB2312", 14, FontStyle.Bold);//设置字体,大小,粗细 7             SolidBrush sbrush = new SolidBrush(Color.White);//设置颜色 8             int base_left = 10; 9             int left_space = 30;10 11             int base_top = 27;12             int top_space = 27;13             for (int i = 0; i < str.Length; i++)14             {15                 if (i > 13)16                 {17                     continue;18                     g.DrawString(str[i] + "", font, sbrush, new PointF(base_left + (left_space * 2), base_top + (top_space * (i - 14))));19                 }20                 else if (i > 6)21                 {22                     g.DrawString(str[i] + "", font, sbrush, new PointF(base_left + (left_space * 1), base_top + (top_space * (i - 7))));23                 }24                 else25                 {26                     g.DrawString(str[i] + "", font, sbrush, new PointF(base_left, base_top + (top_space * i)));27                 }28 29             }30 31             //MemoryStream ms = new MemoryStream();32             //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);33             bmp.Save(@"E:\cover1.png");

字体选择:

黑体:SimHei
宋体:SimSun
新宋体:NSimSun
仿宋:FangSong
楷体:KaiTi
仿宋_GB2312:FangSong_GB2312
楷体_GB2312:KaiTi_GB2312
微软雅黑体:Microsoft YaHei

完结。

以上就是C#给图片增加文字实例代码的详细内容!

相关阅读 >>

浅谈.net中的浅拷贝和深拷贝

c#实现与现有.net事件桥接的简单代码

asp.net开发实用工具

为 jenkins 配置 .net 持续集成环境

c# md5hash的用法及实例

分享一些平时收藏和应用的开源代码

c#中关于async与await的使用详解

介绍c#中的堆和栈

c#中noto sans字体支持韩文的实例教程

c#如何实现json与对象之间互相转换功能示例

更多相关阅读请进入《csharp》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...