- /// <summary>
- /// 图片添加文字
- /// </summary>
- /// <param name="bitmap"></param>
- /// <param name="cont"></param>
- /// <param name="color"></param>
- /// <param name="font"></param>
- /// <returns></returns>
- public static Bitmap ImageAddFont(Bitmap bitmap, string cont, Color color, Font font)
- {
- Graphics g = Graphics.FromImage(bitmap);
- SolidBrush sbrush = new SolidBrush(color);
- g.DrawString(cont, font, sbrush, new PointF(0, 155));
- g.Dispose();
- return bitmap;
- }
- /// <summary>
- /// 圆角矩形
- /// </summary>
- /// <param name="rect">矩形大小</param>
- /// <param name="cornerRadius">为矩形圆角度数</param>
- /// <returns></returns>
- public static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
- {
- GraphicsPath roundedRect = new GraphicsPath();
- roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
- roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
- roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
- roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
- roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
- roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
- roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
- roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
- roundedRect.CloseFigure();
- return roundedRect;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1301201614423.html
来源: http://www.codesnippet.cn/detail/1301201614423.html