asp.net 添加文字水印
来源:互联网 发布:手机遥控汽车软件 编辑:程序博客网 时间:2024/04/29 18:19
/// <summary>
/// 添加水印图片
/// </summary>
/// <param name="fileName">原始图片路径</param>
/// <param name="path_down">保存图片路径</param>\
/// /// <param name="path_down">保存图片名称</param>
private void AddTextToImg(string fileName,string imageSYurl,string imageSYname)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);
Graphics g = Graphics.FromImage(image);
float fontSize = 50; //字体大小
float textWidth = 16 * fontSize; //文本的长度
//下面定义一个矩形区域
float rectX = 0;
float rectY = 261;
float rectWidth = 16 * (fontSize + 8);
float rectHeight = fontSize + 52;
//声明矩形
RectangleF textArea = new RectangleF(181, 361, rectWidth, rectHeight);
RectangleF textArea2 = new RectangleF(181, 500, rectWidth, rectHeight);
Font font = new Font("华文彩云", fontSize); //定义字体
Brush whiteBrush = new SolidBrush(Color.LightGray); //暗黑
Brush blackBrush = new SolidBrush(Color.Transparent); //透明背景
g.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight);
g.DrawString("莱芜市国土资源局", font, whiteBrush, textArea);
if (!string.IsNullOrEmpty(userName))
{
g.DrawString(userName + System.DateTime.Now.ToString("yyyy-MM-dd"), font, whiteBrush, textArea2);
}
else
{
g.DrawString(System.DateTime.Now.ToString("yyyy-MM-dd"), font, whiteBrush, textArea2);
}
//MemoryStream ms = new MemoryStream();
//保存为Jpg类型
//bitmap.Save(ms, ImageFormat.Jpeg);
g.Dispose();
//保存加水印过后的图片,删除原始图片
image.Save(imageSYurl + @"\" + imageSYname.Split('.')[0] + "SY." + imageSYname.Split('.')[1]);
image.Dispose();
if (File.Exists(fileName))
{
File.Delete(fileName);
}
image.Dispose();
}
/// 添加水印图片
/// </summary>
/// <param name="fileName">原始图片路径</param>
/// <param name="path_down">保存图片路径</param>\
/// /// <param name="path_down">保存图片名称</param>
private void AddTextToImg(string fileName,string imageSYurl,string imageSYname)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);
Graphics g = Graphics.FromImage(image);
float fontSize = 50; //字体大小
float textWidth = 16 * fontSize; //文本的长度
//下面定义一个矩形区域
float rectX = 0;
float rectY = 261;
float rectWidth = 16 * (fontSize + 8);
float rectHeight = fontSize + 52;
//声明矩形
RectangleF textArea = new RectangleF(181, 361, rectWidth, rectHeight);
RectangleF textArea2 = new RectangleF(181, 500, rectWidth, rectHeight);
Font font = new Font("华文彩云", fontSize); //定义字体
Brush whiteBrush = new SolidBrush(Color.LightGray); //暗黑
Brush blackBrush = new SolidBrush(Color.Transparent); //透明背景
g.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight);
g.DrawString("莱芜市国土资源局", font, whiteBrush, textArea);
if (!string.IsNullOrEmpty(userName))
{
g.DrawString(userName + System.DateTime.Now.ToString("yyyy-MM-dd"), font, whiteBrush, textArea2);
}
else
{
g.DrawString(System.DateTime.Now.ToString("yyyy-MM-dd"), font, whiteBrush, textArea2);
}
//MemoryStream ms = new MemoryStream();
//保存为Jpg类型
//bitmap.Save(ms, ImageFormat.Jpeg);
g.Dispose();
//保存加水印过后的图片,删除原始图片
image.Save(imageSYurl + @"\" + imageSYname.Split('.')[0] + "SY." + imageSYname.Split('.')[1]);
image.Dispose();
if (File.Exists(fileName))
{
File.Delete(fileName);
}
image.Dispose();
}
0 0
- asp.net 添加文字水印
- asp.net为图片添加文字水印
- Asp添加文字水印
- ASP.NET 给图片动态添加文字水印
- asp.net实现图片添加文字及图片水印
- ASP.NET 给图片动态添加文字水印
- ASP.NET 上传图片添加文字、Logo水印
- Asp.Net添加水印
- ASP.NET(C#)缩略图片,添加文字水印和图片水印
- ASP.NET实现简单的文字水印
- asp .net 为图片添加文字水印(内包含有加图片水印的方法,但尚未完善暂不能使用)
- ASP.NET图片上传,加水印文字和水印图片!
- asp.net动态添加图片水印
- asp .net 为图片添加图片水印
- asp.net 给图片添加水印
- asp.net 给图片添加水印
- ASP.NET Ueditor上传图片添加水印
- Java添加水印+图片水印+文字水印
- js数组去重的4种方法
- JavaScript学习-函数
- Qt 5.x中出现中文乱码的解决方法
- linux命令
- [bzoj4305]数列的gcd
- asp.net 添加文字水印
- 《视频直播技术详解》系列之三:处理
- 第二天的学习
- JAVA 设计模式、虚拟机体系结构、JavaScript
- 蓝桥杯-瓷砖摆放-递推-java
- 【Unity】游戏开发过程中的前后台切换技术
- html 标签学习-列表标签
- 单链表逆置-java(递归与非递归)
- oracle 在一张日志表中,同一个ID 有多条记录,每个ID只获取最新时间的记录