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);
}
}
查看全文
相关阅读:
Objective-C method及相关方法分析
java对象和json数据转换实现方式1-使用json-lib实现
java中TCP传输协议
【剑指Offer学习】【面试题27:二叉搜索树与双向链表】
4.2.2 MINUS
Hadoop for .NET Developers
在命名空间下定义类型
Android NDK课程录制完毕上线
全然同态加密
从golang的垃圾回收说起(下篇)
原文地址:https://www.cnblogs.com/zjz/p/265664.html
最新文章
常见web安全攻防总结
在Flask中使用Celery的最佳实践
二十三种设计模式及其python实现
常见设计模式 (python代码实现)
设计模式(Python)-策略模式
设计模式(Python)-简单工厂,工厂方法和抽象工厂模式
设计模式(Python)-单例模式
Python中的单例模式的几种实现方式的及优化
Python协程 Gevent Eventlet Greenlet
数组中重复的数字
热门文章
把字符串转换成整数
不用加减乘除做加法
求1+2+3+...+n
孩子们的游戏(圆圈中最后剩下的数)——约瑟夫问题
扑克牌顺子
深入理解C++的动态绑定和静态绑定
翻转单词顺序列
左旋转字符串
和为S的两个数字
JavaScript版MD5应用
Copyright © 2011-2022 走看看