• 记录-C#给图片增加文字


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

    测试代码:

     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                 else
    25                 {
    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

    完结。

  • 相关阅读:
    修改默认runlevel
    shell数学运算
    Ubuntu碎碎念
    编译Linux-2.6.23内核中遇见的错误
    CentOS设置静态IP
    多线程--对象锁和类锁
    [Unity移动端]Touch类
    [Lua]string与中文
    MQTT 5.0 新特性(四)Clean Start 与 Session Expiry Interval
    EMQ 9 月 新发 | EMQ X Enterprise 3.4.0 功能概览
  • 原文地址:https://www.cnblogs.com/kongkonglonglong/p/7020085.html
Copyright © 2020-2023  润新知