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);
}
}
查看全文
相关阅读:
中国剩余定理(CRT) & 扩展中国剩余定理(ExCRT)总结
各种求逆元
A*(A_star)搜索总结
线段树总结
C++的STL
Unable to make the session state request to the session state server处理方法
判断UserAgent是否来自微信
VS2010 EntityFramework Database First
VS2010类似Eclipse文件查找功能-定位到
Newtonsoft.Json随手记
原文地址:https://www.cnblogs.com/it563/p/584970.html
最新文章
Am335x SD卡 启动制作
Am335x U-boot LCD简易驱动
Am335x u-boot 启动过程中的系统频率配置
linux-ARM的几个使用指令
python之chardet用来检测字符串编码的
python连接mongodb集群
ruby之基础语法
postgres之清理空间碎片
postgres之使用python连接并操作
postgres服务之加密以及public-schema删除后的问题和处理
热门文章
postgres服务安装,启动和配置
pipeline语法之environment,dir(),deleteDir()方法,readJSON,writeJSON
pipeline语法之判断一个文件存在与否
不务正业(嘘!)
BZOJ4753: [Jsoi2016]最佳团体(分数规划+树上背包)
CF912E Prime Gift题解(搜索+二分答案)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp&Floyd$)
基数排序总结
洛谷P2460 [SDOI2007]科比的比赛(题解)(贪心+搜索)
欧拉函数&欧拉定理&降幂 总结
Copyright © 2011-2022 走看看