- 微信小程序中var、let、const的用法及区别
- 百度优化能够杜绝人工干预
- 如何让你的网站受到搜索引擎的青睐?
- 移动控件介绍及详细使用方法:AdRotator移动控件
- require和require-dev的区别
- 浅谈修改网站标题利与弊
- javascript:void(0)
- C#中字段和属性的区别 .
- SEO基础细节:nofollow的介绍与应用
- npm 和 cnpm 的区别
邮箱:
手机:15383239821
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);
}
}
-
2013-11-13display:inline、block、inline-block的区别
-
2019-11-21C#实例化类的方式
-
2013-10-24使用Javascript防止重复提交表单
-
2013-11-22.net中sql语句的安全性
-
2023-06-09域名赎回期要收费吗?赎回期域名如何赎回?
-
2012-07-02如何优化你的网站.

