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);
}
}
查看全文
相关阅读:
Java 设计模式(2)工厂模式
Java 设计模式-六大原则
华为机试测试- 求有序数组中最长的等差序列
JAVA SE 基础复习-面向对象(2) static
Java 设计模式
Java 字符串
jQuery源代码学习之七—队列模块queue
jQuery源代码学习之六——jQuery数据缓存Data
jQuery源代码学习之五——jQuery.when
javascript源代码学习之五——jQuery.deferred
原文地址:https://www.cnblogs.com/it563/p/584970.html
最新文章
纯css实现移动端横向滑动列表(可应用于ionic3移动app开发)
四种webAPP横向滑动模式图解—H5页面开发
神器扒网站——teleport ultra
前端学习计划
html5 流式布局 弹式布局 flex
前端博站项目中遇到的问题总结
记一次排查jacoco的过程:java.lang.NoSuchMethodException:ApplyOrderdetail.get$jacocoData()
详解数据库连接池概念、原理、运行机制等
mysql数据库去掉字符前/中/后的空格
mysql实现行转列功能
热门文章
记一次生产kafka消息消费的事故
逻辑分页与物理分页的区别
在eclipse中新建java问题报错:The type XXX cannot be resolved. It is indirectly referenced from required .class files
Http状态码梳理汇总
使用PostMan进行压力/性能测试
HashMap实现原理及源码分析
找出两个点之间的所有路径(原创)
约瑟夫环之递归实现
Java 设计模式(4)适配器模式
Java 设计模式(3)单例模式
Copyright © 2011-2022 走看看