测试代码:
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#给图片增加文字实例代码的详细内容,更多请关注php中文网其它相关文章!
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
程序员必备接口测试调试工具:点击使用
Apipost = Postman + Swagger + Mock + Jmeter
Api设计、调试、文档、自动化测试工具
网页生成APP,用做网站的技术去做APP:立即创建
手机网站开发APP、自助封装APP、200+原生模块、2000+映射JS接口按需打包
相关文章
相关视频