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);
}
}
查看全文
相关阅读:
杂
修改 linux 时区时间和 php 时区
夺命雷公狗—玩转SEO---21---域名购买技巧
夺命雷公狗—玩转SEO---20---K站
夺命雷公狗—玩转SEO---19---降权
夺命雷公狗—玩转SEO---18---索引
夺命雷公狗—玩转SEO---17---收录
夺命雷公狗—玩转SEO---16---关键词词性和定位关键词
夺命雷公狗—玩转SEO---15---域名
夺命雷公狗—玩转SEO---14---空间和服务器的区别
原文地址:https://www.cnblogs.com/it563/p/584970.html
最新文章
angularJS 分页
JPA派生标识符2
Spring Boot控制上传文件大小
JPA单向和双向关系
JPA 派生标识符的两种实现方式
JPA 唯一索引
getLong not implemented for class oracle.jdbc.driver.T4CRowidAccessor
慎用子查询,因为难以优化
断电后gitlab报500错误启动出错
ORACLE的WITH语句的一个疑惑
热门文章
iptables开放所有端口
Tomcat中配置多个端口
NetBeans无法使用编码GBK安全地打开该文件(改为默认UTF-8)
juery与表单中name="nodeName"引起的冲突
用SYS_CONNECT_BY_PATH进行层级查询时的排序问题
“ORA-01033:ORACLE initialization or shutdown in progress”错误的解决
Laravel (三) 邮件通知,自定义通通知
一段PHP异常
微信小程序
安装 nodejs
Copyright © 2011-2022 走看看