C#在图片增加文字的实现代码

作者:空空隆隆 时间:2023-03-30 03:26:24 

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

测试代码:


string path = @"E:\cover.png";
     Bitmap bmp = new Bitmap(path);
     Graphics g = Graphics.FromImage(bmp);
     String str = "贤愚经";
     Font font = new Font("仿宋_GB2312", 14, FontStyle.Bold);//设置字体,大小,粗细
     SolidBrush sbrush = new SolidBrush(Color.White);//设置颜色
     int base_left = 10;
     int left_space = 30;
     int base_top = 27;
     int top_space = 27;
     for (int i = 0; i < str.Length; i++)
     {
       if (i > 13)
       {
         continue;
         g.DrawString(str[i] + "", font, sbrush, new PointF(base_left + (left_space * 2), base_top + (top_space * (i - 14))));
       }
       else if (i > 6)
       {
         g.DrawString(str[i] + "", font, sbrush, new PointF(base_left + (left_space * 1), base_top + (top_space * (i - 7))));
       }
       else
       {
         g.DrawString(str[i] + "", font, sbrush, new PointF(base_left, base_top + (top_space * i)));
       }
     }
     //MemoryStream ms = new MemoryStream();
     //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
     bmp.Save(@"E:\cover1.png");

字体选择:

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

以上所述是小编给大家介绍的C#在图片增加文字的实现代码网站的支持!

来源:http://www.cnblogs.com/kongkonglonglong/archive/2017/06/15/7020085.html

标签:c#,图片,增加文字
0
投稿

猜你喜欢

  • Feign远程调用Multipartfile参数处理

    2022-09-22 02:46:24
  • java状态机方案解决订单状态扭转示例详解

    2022-01-10 02:55:43
  • SpringBoot注入自定义的配置文件的方法详解

    2021-12-24 02:28:06
  • java构造函数示例(构造方法)

    2022-05-08 19:06:03
  • Java访问Hadoop分布式文件系统HDFS的配置说明

    2021-11-20 05:53:42
  • Maven构建生命周期详细介绍

    2023-04-06 13:02:59
  • java两个integer数据判断相等用==还是equals

    2021-06-14 00:46:52
  • 详解SpringBoot配置连接池

    2022-03-28 13:29:42
  • 基于SSM框架+Javamail发送邮件的代码实例

    2022-04-28 11:59:04
  • SpringBoot自定义加载yml实现方式,附源码解读

    2022-01-22 22:39:40
  • 利用C#实现SSLSocket加密通讯的方法详解

    2023-03-01 02:23:05
  • Android 内存优化知识点梳理总结

    2021-05-24 02:54:19
  • Android仿新浪微博发送菜单界面的实现

    2022-12-13 10:54:03
  • SpringBoot整合Mybatis简单实现增删改查

    2023-07-05 15:33:44
  • Springboot-注解-操作日志的实现方式

    2023-10-10 13:54:35
  • springboot项目如何防止XSS攻击

    2021-10-17 10:03:02
  • C#实现根据指定容器和控件名字获得控件的方法

    2023-09-26 12:23:03
  • Java中的线程生命周期核心概念

    2021-10-14 13:37:54
  • Java集合中的fail-fast(快速失败)机制详解

    2023-05-10 16:31:33
  • C#使用BackgroundWorker控件

    2022-10-25 05:06:35
  • asp之家 软件编程 m.aspxhome.com