项目的一个小需求,以此做笔记~
int txt_Font_Size = 24;//上面文本的字号 int txt_margin_left_and_right = 62;//文本两边的距离 using (Graphics g = Graphics.FromImage(haibao)) { //设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //下面这个也设成高质量 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //下面这个设成High g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; float fontSize = txt_Font_Size; //字体大小 float textWidth = text.Length * fontSize; //文本的长度 float rectX = txt_margin_left_and_right; float rectY = 200; float rectWidth = haibao.Width - (txt_margin_left_and_right * 2); float rectHeight = fontSize + 40; RectangleF textArea = new RectangleF(rectX, rectY, rectWidth, haibao.Height);//文本域 Font font = new Font("宋体", fontSize, FontStyle.Bold); //定义字体 Brush whiteBrush = new SolidBrush(Color.White);//笔刷 g.DrawString(text, font, whiteBrush, textArea, StringFormat.GenericDefault); }
微信扫码查看本文
发表评论