以下代码实现在图片上写字,在图片上画线:
/// <summary> /// 在图片上写字 /// </summary> /// <param name="img">原图</param> /// <param name="words">要写的内容</param> /// <param name="font">字体</param> /// <param name="brush">笔刷</param> /// <param name="x">横坐标</param> /// <param name="y">纵坐标</param> /// <returns></returns> public static Image DrawWordsOnPicture(Image img,string words,Font font,Brush brush,int x,int y) { Graphics g = Graphics.FromImage(img); PointF p = new PointF(x, y); g.DrawString(words, font, brush, p); return img; } /// <summary> /// 在图片上画线 /// </summary> /// <param name="img">原图</param> /// <param name="color">颜色</param> /// <param name="brushWidth">笔刷宽度</param> /// <param name="startX">起始横坐标</param> /// <param name="startY">起始纵坐标</param> /// <param name="endX">结束横坐标</param> /// <param name="endY">结束纵坐标</param> /// <returns></returns> public static Image DrawLineOnPicture(Image img,Color color,int brushWidth,int startX,int startY,int endX,int endY) { Graphics g = Graphics.FromImage(img); Pen pen = new Pen(color, brushWidth); g.DrawLine(pen, startX, startY, endX, endY); return img; }
评论前必须登录!
注册