基本信息
源码名称:ASP.NET上传图片生成水印效果
源码大小:0.38M
文件格式:.zip
开发语言:ASP
更新时间:2019-02-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
ASP.NET上传图片生成水印效果
{
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/png")
{
string name = FileUpload1.PostedFile.FileName; // 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = file.Name; // 文件名称
string fileName_s = "x_" file.Name; // 缩略图文件名称
string fileName_sy = "text_" file.Name; // 水印图文件名称(文字)
string fileName_syp = "water_" file.Name; // 水印图文件名称(图片)
string webFilePath = Server.MapPath("ImgUpload/" fileName); // 服务器端文件路径
string webFilePath_s = Server.MapPath("ImgUpload/" fileName_s); // 服务器端缩略图路径
string webFilePath_sy = Server.MapPath("ImgUpload/" fileName_sy); // 服务器端带水印图路径(文字)
string webFilePath_syp = Server.MapPath("ImgUpload/" fileName_syp); // 服务器端带水印图路径(图片)
string webFilePath_sypf = Server.MapPath("51aspx.png"); // 服务器端水印图路径(图片)
if (!File.Exists(webFilePath))
{
try
{
FileUpload1.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
AddWater(webFilePath, webFilePath_sy);
AddWaterPic(webFilePath, webFilePath_syp, webFilePath_sypf);
MakeThumbnail(webFilePath, webFilePath_s, 130, 130, "Cut"); // 生成缩略图方法
Label1.Text = "提示:文件“" fileName "”成功上传,并生成“" fileName_s "”缩略图,文件类型为:" FileUpload1.PostedFile.ContentType ",文件大小为:" FileUpload1.PostedFile.ContentLength "B";
}
catch (Exception ex)
{
Label1.Text = "提示:文件上传失败,失败原因:" ex.Message;
}
}
else
{
Label1.Text = "提示:文件已经存在,请重命名后上传";
}
}
else
{
Label1.Text = "提示:文件类型不符";
}
}
}
ASP.NET上传图片生成水印效果
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/png")
{
string name = FileUpload1.PostedFile.FileName; // 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = file.Name; // 文件名称
string fileName_s = "x_" file.Name; // 缩略图文件名称
string fileName_sy = "text_" file.Name; // 水印图文件名称(文字)
string fileName_syp = "water_" file.Name; // 水印图文件名称(图片)
string webFilePath = Server.MapPath("ImgUpload/" fileName); // 服务器端文件路径
string webFilePath_s = Server.MapPath("ImgUpload/" fileName_s); // 服务器端缩略图路径
string webFilePath_sy = Server.MapPath("ImgUpload/" fileName_sy); // 服务器端带水印图路径(文字)
string webFilePath_syp = Server.MapPath("ImgUpload/" fileName_syp); // 服务器端带水印图路径(图片)
string webFilePath_sypf = Server.MapPath("51aspx.png"); // 服务器端水印图路径(图片)
if (!File.Exists(webFilePath))
{
try
{
FileUpload1.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
AddWater(webFilePath, webFilePath_sy);
AddWaterPic(webFilePath, webFilePath_syp, webFilePath_sypf);
MakeThumbnail(webFilePath, webFilePath_s, 130, 130, "Cut"); // 生成缩略图方法
Label1.Text = "提示:文件“" fileName "”成功上传,并生成“" fileName_s "”缩略图,文件类型为:" FileUpload1.PostedFile.ContentType ",文件大小为:" FileUpload1.PostedFile.ContentLength "B";
}
catch (Exception ex)
{
Label1.Text = "提示:文件上传失败,失败原因:" ex.Message;
}
}
else
{
Label1.Text = "提示:文件已经存在,请重命名后上传";
}
}
else
{
Label1.Text = "提示:文件类型不符";
}
}
}