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);
}
}
查看全文
相关阅读:
Python数据结构与算法—栈
var_export 和 var_dump
PHp 下标是 区分大小写的
和眼睛相处
css 3 animation
background-attachment: fixed | attachment 区别
js 函数表达和函数声明
function 和 new Function
lastIndexOf js
substring substr slice js比较
原文地址:https://www.cnblogs.com/zjz/p/265664.html
最新文章
70. Climbing Stairs Java Solutin
283. Move Zeroes Leetcode Java Solutin
《算法导论》笔记---附录 B.5 树
[转]JavaSE 8—新的时间和日期API
chrome密码管理
[转]JDK6和JDK7中的substring()方法
[转]Java 泛型: 什么是PECS(Producer Extends, Consumer Super)
[转]Arrays.sort()你应该知道的事
[转]开发者需要了解的WebKit(mark)
[转]Integer.valueOf(String) 方法之惑
热门文章
Notepad++ 配置java编译环境
Excel VBA记录
Python网络编程—套接字属性
Python网络编程—socket套接字编程(UDP)
Python网络编程—socket套接字编程(TCP)
Python网络编程(二)
Python网络编程(一)
Python数据结构与算法—排序和查找
Python数据结构与算法—树形结构、二叉树
Python数据结构与算法—队列
Copyright © 2011-2022 走看看