Recent projects need to dynamically add text to the picture (book cover picture), modify the font size, font, color, control position, etc., below through the example code to share C # in the picture to add text implementation code, together to see it
Business needs to dynamically add text to the picture (the book's cover picture), modify the font size, font, color, control location
Test code:
string path = @ "E:\cover.png"; Bitmap bmp = new Bitmap (path); Graphics g = graphics.fromimage (BMP); String str = "Yin Folly"; Font font = new Font ("Imitation _gb2312", +, fontstyle.bold);//Set font, size, weight solidbrush Sbrush = new SolidBrush (color.white);// Set color 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 >) {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_spa CE * 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");
Font selection:
Blackbody: Simhei
Song Body: SimSun
New song body: Nsimsun
Imitation: Fangsong
Italics: Kaiti
Imitation _gb2312:fangsong_gb2312
Italic _gb2312:kaiti_gb2312
Microsoft Elegance Blackbody: Microsoft Yahei