Record-C # add text to the image,
Business needs to dynamically add text to images (cover pictures of books), modify font size, Font, color, and control position
Test code:
1 string path = @ "E: \ cover.png"; 2 3 Bitmap bmp = new Bitmap (path); 4 Graphics g = Graphics. fromImage (bmp); 5 String str = "Yin Yu Jing"; 6 Font font = new Font (" _ GB2312", 14, FontStyle. bold); // set the font, size, and width. The value is 7. white); // set the color to 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; 18g. 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 {22g. drawString (str [I] + "", font, sbrush, new PointF (base_left + (left_space * 1), base_top + (top_space * (I-7 )))); 23} 24 else25 {26g. 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 ");
Font selection:
SimHei
SimSun
New: NSimSun
Imitation Song: FangSong
KaiTi
Imitation Song _ GB2312: FangSong_GB2312
_ GB2312: KaiTi_GB2312
Microsoft YaHei
End.