業務需要動態給圖片增加文字(書本的封面圖片),修改字體大小、字體、顏色、控制位置
測試代碼:
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#在圖片增加文字的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答