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#给图片增加文字实例代码的详细内容!

相关阅读 >>

c#中方向键与回车键切换控件焦点的两种方法

c#cs与bs数据请求交换

c#如何使用键值对取代switch...case语句的示例

c#中关于list<t>的并集与交集以及差集解析

.net core中如何使用ref和span<t>提高程序性能的实现代码

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

关于c#如何实现access以时间段查询出来的的数据添加到listview中

c#如何使用libusbdotnet实现usb通信的示例详解

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

c#使用free spire.presentation实现对ppt插入与编辑以及删除表格

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




打赏

取消

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

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

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

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

评论

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