zoukankan
html css js c++ java
给图片加上水印效果
private
void
Btn_Upload_Click(
object
sender, System.EventArgs e)
{
if
(UploadFile.PostedFile.FileName.Trim()
!=
""
)
{
//
上传文件
string
extension
=
Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
string
fileName
=
DateTime.Now.Year.ToString()
+
DateTime.Now.Month.ToString()
+
DateTime.Now.Day.ToString()
+
DateTime.Now.Hour.ToString()
+
DateTime.Now.Minute.ToString()
+
DateTime.Now.Second.ToString();
string
path
=
Server.MapPath(
"
.
"
)
+
"
/UploadFile/
"
+
fileName
+
extension;
UploadFile.PostedFile.SaveAs(path);
//
加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
System.Drawing.Image image
=
System.Drawing.Image.FromFile(path);
Graphics g
=
Graphics.FromImage(image);
g.DrawImage(image,
0
,
0
, image.Width, image.Height);
Font f
=
new
Font(
"
Verdana
"
,
32
);
Brush b
=
new
SolidBrush(Color.White);
string
addText
=
AddText.Value.Trim();
g.DrawString(addText, f, b,
10
,
10
);
g.Dispose();
//
加图片水印
System.Drawing.Image image
=
System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage
=
System.Drawing.Image.FromFile( Server.MapPath(
"
.
"
)
+
"
/Alex.gif
"
);
Graphics g
=
Graphics.FromImage(image);
g.DrawImage(copyImage,
new
Rectangle(image.Width
-
copyImage.Width, image.Height
-
copyImage.Height, copyImage.Width, copyImage.Height),
0
,
0
, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
g.Dispose();
//
保存加水印过后的图片,删除原始图片
string
newPath
=
Server.MapPath(
"
.
"
)
+
"
/UploadFile/
"
+
fileName
+
"
_new
"
+
extension;
image.Save(newPath);
image.Dispose();
if
(File.Exists(path))
{
File.Delete(path);
}
Response.Redirect(newPath);
}
}
查看全文
相关阅读:
在 Linux 下搭建 Git 服务器***
使用 SVN Hook 实现服务器端代码自动更新
git服务器的建立
Oracle 11gR2 RAC集群服务启动与关闭总结
Cluster的日记体系
DB time VS. DB CPU
oracle 内存分配和调优 总结
利用logminer恢复delete误删除操作的数据
大话RAC介质恢复---联机日志损坏
ORACLE联机日志文件丢失或损坏的处理方法(转)
原文地址:https://www.cnblogs.com/zjz/p/265664.html
最新文章
效率清单
古人与古代(他们和他们的时代)之西方篇
Guided Image Filtering
Windows Server Backup 2008 R2 备份Hyper-V
Netsh配置端口
查看sid
Update-ServiceTemplate
配置Outlook Anywhere2010
服务启动停止配置
部署应用程序QQ
热门文章
OAB配置
删除隐藏网卡
hotfix分析
gerrit使用总结
SVN工具使用技巧
gitweb
配置文件git config介绍
在CentOS下搭建自己的Git服务器
ubuntu 12.04.5 LTS版本 更新 source.list
VMware 虚拟机下挂载U盘
Copyright © 2011-2022 走看看