C# 给图片添加水印或者建立空白画布加水印简单方法
//文字水印方法
//--Author :lc
public Bitmap CreateBit(Bitmap img, int width, int height)
{
FontStyle ff = 0;//设置样式
Bitmap bmp = img == null ? new Bitmap(width, height) : img;//是否存在原图片,不存在就按照 高宽 重新建立一张画布
Graphics g;//创建Graphics
if (img == null)
{
g = Graphics.FromImage(bmp);
System.Drawing.Rectangle c = new System.Drawing.Rectangle(0, 0, width, height);
g.FillRectangle(Brushes.White, c);//白色底色填充
}
else
g = Graphics.FromImage(img);
g.DrawString(Config.email, new System.Drawing.Font("宋体", 20, ff), Brushes.Red, new PointF(width / 2 - Config.email.Length * 8, height / 2));//在画布中添加水印
return bmp;
}
posted on 2012-09-03 13:48 JQuery-Ch 阅读(1054) 评论(0) 编辑 收藏 举报