您好,登錄后才能下訂單哦!
小編給大家分享一下C#給圖片增加文字的方法,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
業(yè)務(wù)需要?jiǎng)討B(tài)給圖片增加文字(書本的封面圖片),修改字體大小、字體、顏色、控制位置
測試代碼:
1 string path = @"E:\cover.png"; 2 3 Bitmap bmp = new Bitmap(path); 4 Graphics g = Graphics.FromImage(bmp); 5 String str = "賢愚經(jīng)"; 6 Font font = new Font("仿宋_GB2312", 14, FontStyle.Bold);//設(shè)置字體,大小,粗細(xì) 7 SolidBrush sbrush = new SolidBrush(Color.White);//設(shè)置顏色 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 else25 {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
看完了這篇文章,相信你對(duì)“C#給圖片增加文字的方法”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。