using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace 图片水印
{
/// <summary>
/// 水印类
/// </summary>
public class WaterMark
{
private string ImagePath = null;
private Image bm = null;
public WaterMark() { }
public WaterMark(string ImagePath)
{
this.ImagePath = ImagePath;
}
public WaterMark(Image b)
{
this.bm = b;
}
public Image Draw(string content)
{
Image image = null;
if (ImagePath != null)
{
try
{
image = Image.FromFile(this.ImagePath);
}
catch
{
return null;
}
}
if (bm != null)
{
image = this.bm;
}
Graphics g = Graphics.FromImage(image);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Far;
RectangleF rf = new RectangleF(0,0,image.Width,image.Height);
g.DrawString(content, new Font("宋体", 40), Brushes.Red,rf,sf);
g.Dispose();
return image;
}
}
}
Hold on, everything is possible.