zoukankan
html css js c++ java
Asp.net(C#)给图片加上水印效果
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);
}
}
查看全文
相关阅读:
SVG.js 文本绘制整理
SVG.js 基础图形绘制整理(二)
SVG.js 基础图形绘制整理(一)
C# 异步编程Task整理(一)
Svg.Js 父类的基础操作
Svg.Js A标签,链接操作
Svg.Js 简介(转)
SVG 相关整理
Kendo UI
Kendo UI
原文地址:https://www.cnblogs.com/King0502/p/2019277.html
最新文章
什么是指令周期?什么是机器周期?什么是时钟周期?三者之间的关系如何?
Z路径覆盖
代码走查与代码审查区别
数据库三范式
使用appscan实现多站扫描简单自动化
Linux平台Java调用so库-JNI使用例子
利用appscan进行自动化定期安全测试
一款免费好用的正则表达式工具:Regex Match Tracer
Asp.Net Core MVC控制器和视图之间传值
.NetCore中EFCore的使用整理
热门文章
Asp.Net WebApi开启Session回话
SVG.js 元素操作整理(二)-Transform
SVG.js 元素操作整理(一)
SVG.js 引用获取整理
SVG.js Marker标记和自定义标签
SVG.js Mask覆盖和ClipPath裁剪
SVG.js 图案使用和use引用
Asp.Net Mvc表单提交之List集合
SVG.js 颜色渐变使用
Svg.js 图片加载
Copyright © 2011-2022 走看看