C # Add text instance code to a picture

Source: Internet
Author: User
Business needs to dynamically add text to the picture (the book's cover picture), modify the font size, font, color, control location

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 ("Imitation _gb2312", fontstyle.bold);//Set font, size, weight 7 solidbrush sbrush = new Sol Idbrush (Color.White);//Set color 8 int base_left = 10;  9 int left_space = 30;10 int base_top = 27;12 int top_space = 27;13 for (int i = 0; i < str.) Length;                     i++) {if (i >) + continue;18 g.DrawString (Str[i] + "", Font, Sbrush, new PointF (Base_left + (Left_space * 2), Base_top + (Top_space * (I-14))))  ;}20 else if (i > 6) {g.drawstring (Str[i] + "", Font, Sbrush, new PointF (Base_left + (Left_space * 1), Base_top + (Top_space * (i-7))); 23}24 Else25 {g.drawstring (Str[i] + "", Font, Sbrush, new PointF (base_l EFT, Base_top + (Top_space * i));}28}30//memorystream ms = new Memorys Tream ();//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

End.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.