/// <summary>
/// 給圖片添加文字水印
/// </summary>
/// <param name="img">圖片</param>
/// <param name="text">文字</param>
/// <param name="p">文本位置中心點(diǎn)坐標(biāo)</param>
/// <param name="font">字體</param>
/// <param name="fontColor">字體顏色</param>
/// <param name="angle">旋轉(zhuǎn)角度(順時(shí)針)</param>
/// <returns></returns>
public static Image AddText2Image(Image img, string text,Point p, Font font, Color fontColor, int angle)
{
using ( var g = Graphics.FromImage(img))
using ( var brush= new SolidBrush(fontColor))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
var sizeF = g.MeasureString(text,font);
g.ResetTransform();
g.TranslateTransform(p.X,p.Y);
g.RotateTransform(angle);
g.DrawString(text,font,brush, new PointF(-sizeF.Width/2,-sizeF.Height/2));
}
return img;
}
|