给服务器上的指定的图片添加文字水印
来源:互联网 发布:win7的c语言编程软件 编辑:程序博客网 时间:2024/04/30 01:27
public class ImageWater {
public enum WaterPosition
{
TopRight,
TopMiddle,
TopLeft,
BottomRight,
BottomMiddle,
BottomLeft
}
/// <summary>
/// 添加文字水印
/// </summary>
/// <param name="picPath">图片在服务器上的绝对路径</param>
/// <param name="words">要向图片上添加的水印文字</param>
public static void AddWordWaterToImg(string picPath, string words, WaterPosition wposition)
{
Image image = Image.FromFile(picPath);
Bitmap b = new Bitmap(image.Width, image.Height,
PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("宋体", 12);
Brush brush = new SolidBrush(System.Drawing.Color.Green);
SizeF sizef = new SizeF();
sizef = g.MeasureString(words, f);//获取文字的大小
float xpos = 12;
float ypos = 12;
switch (wposition)
{
case WaterPosition.TopLeft:
xpos = 12;
ypos = 12;
break;
case WaterPosition.TopMiddle:
xpos = image.Width / 2 - sizef.Width / 2;
ypos = 12;
break;
case WaterPosition.TopRight:
xpos = image.Width - (sizef.Width+xpos);
ypos = 12;
break;
case WaterPosition.BottomLeft:
xpos = 12;
ypos = image.Height - (sizef.Height+ypos);
break;
case WaterPosition.BottomMiddle:
xpos = image.Width / 2 - sizef.Width / 2;
ypos = image.Height - (sizef.Height + ypos);
break;
case WaterPosition.BottomRight:
xpos = image.Width - (sizef.Width + xpos);
ypos = image.Height - (sizef.Height + ypos);
break;
default:
break;
}
g.DrawString(words, f, brush, xpos, ypos);
image.Dispose();
b.Save(picPath);
b.Dispose();
}
}
public enum WaterPosition
{
TopRight,
TopMiddle,
TopLeft,
BottomRight,
BottomMiddle,
BottomLeft
}
/// <summary>
/// 添加文字水印
/// </summary>
/// <param name="picPath">图片在服务器上的绝对路径</param>
/// <param name="words">要向图片上添加的水印文字</param>
public static void AddWordWaterToImg(string picPath, string words, WaterPosition wposition)
{
Image image = Image.FromFile(picPath);
Bitmap b = new Bitmap(image.Width, image.Height,
PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("宋体", 12);
Brush brush = new SolidBrush(System.Drawing.Color.Green);
SizeF sizef = new SizeF();
sizef = g.MeasureString(words, f);//获取文字的大小
float xpos = 12;
float ypos = 12;
switch (wposition)
{
case WaterPosition.TopLeft:
xpos = 12;
ypos = 12;
break;
case WaterPosition.TopMiddle:
xpos = image.Width / 2 - sizef.Width / 2;
ypos = 12;
break;
case WaterPosition.TopRight:
xpos = image.Width - (sizef.Width+xpos);
ypos = 12;
break;
case WaterPosition.BottomLeft:
xpos = 12;
ypos = image.Height - (sizef.Height+ypos);
break;
case WaterPosition.BottomMiddle:
xpos = image.Width / 2 - sizef.Width / 2;
ypos = image.Height - (sizef.Height + ypos);
break;
case WaterPosition.BottomRight:
xpos = image.Width - (sizef.Width + xpos);
ypos = image.Height - (sizef.Height + ypos);
break;
default:
break;
}
g.DrawString(words, f, brush, xpos, ypos);
image.Dispose();
b.Save(picPath);
b.Dispose();
}
}
- 给服务器上的指定的图片添加文字水印
- JAVA给图片上添加水印文字
- 给图片添加透明文字水印的方法
- 给图片添加文字水印
- 给图片添加文字水印
- 图片上添加自定义字体的文字水印
- 给上传的图片增加文字水印
- Java给图片添加图片、文字水印
- 给图片添加水印图片文字
- 给图片添加水印效果图的函数(可以在图片上添加自己的版权和LOGO图片的水印)
- 给图片添加水印效果图的函数(可以在图片上添加自己的版权和LOGO图片的水印)
- 在图片添加旋转的水印文字
- java给图片添加水印文字
- php给图片添加文字水印
- java给图片添加水印文字
- IOS给图片添加文字水印
- java给图片添加水印文字
- Java给图片添加文字水印
- c语言字节对齐
- tcp keep_alive
- 石子合并问题--直线版
- 百度联盟图文混排产品形式上线增设图标等元素
- SUSE LINIUX 安装Memcached
- 给服务器上的指定的图片添加文字水印
- 复制表的时候为什么约束会丢失
- 软件开发团队主管易犯的十个错误
- 管道和FIFO的非阻塞I/O
- 如何判断对话框已经初始化
- 左键点击转化为角度
- Bresenham算法
- 乔布斯办公室语录
- 生活中的感动