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);
}
}
查看全文
相关阅读:
eclipse 64和32位切换
把web项目部署到阿里云linux服务器上
CDN工作过程(第二种版本)
CDN的基本工作过程
第五课 JAVA反射获取对象属性和方法(通过配置文件)
第五课 JAVA反射获取对象属性和方法
第四课:通过配置文件获取对象(Spring框架中的IOC和DI的底层就是基于这样的机制)
第三课:JAVA反射机制
爬虫基本操作、requests和BeautifulSoup
孤荷凌寒自学python第十八天python变量的作用范围
原文地址:https://www.cnblogs.com/it563/p/584970.html
最新文章
将字符串转换成16进制字节数组和16进制数组的小方法
[R] 如何在Linux命令行进行参数传入?
[Linux] Miniconda安装及其使用
[Linux]非root的R环境被conda破坏后如何恢复?
[Linux] 非root安装GCC9.1.0
[R] 如何绘制各样本的pathway丰度热图?
[R] venn.diagram保存pdf格式文件?
[linux] 非root安装Python2及其模块
[Linux] 非root安装Lefse软件及其数据分析
[linux] rm -rf删除软链接无权限?
热门文章
[linux] mv: cannot move $ to $: Directory not empty
java项目开发第六天——天若有情天亦老,人间正道是沧桑
java项目开发第五天——奋力完成数据库
洛谷——P1034 矩形覆盖
POJ——T 1160 Post Office
BZOJ——T 2097: [Usaco2010 Dec]Exercise 奶牛健美操
BZOJ——T 4563: [Haoi2016]放棋子
CODEVS——T 1036 商务旅行
RabbitMQ(二)
Freemarker简单用法
Copyright © 2011-2022 走看看